Kompilatorfel CS0662

Metoden kan inte bara ange utattribut för en referensparameter. Använd både In- och Out-attribut eller ingetdera.

En gränssnittsmetod har en parameter som använder referens med bara out-attributet. En ref parameter som använder attributet Out måste också använda attributet In .

Följande exempel genererar CS0662:

// CS0662.cs  
using System.Runtime.InteropServices;  
  
interface I  
{  
   void method([Out] ref int i);   // CS0662  
   // try one of the following lines instead  
   // void method(ref int i);  
   // void method([Out, In]ref int i);  
}  
  
class test  
{  
   public static void Main()  
   {  
   }  
}