编译器错误 CS0177

更新:2007 年 11 月

错误消息

控制离开当前方法之前必须对输出参数“parameter”赋值

在方法体中没有给用 out 关键字标记的参数赋值。有关更多信息,请参见传递参数(C# 编程指南)

下面的示例生成 CS0177:

// CS0177.cs
public class MyClass
{
   public static void Foo(out int i)   // CS0177
   {
   // uncomment the following line to resolve this error
   //   i = 0;
   }

   public static void Main()
   {
       int x = -1;
       Foo(out x);
   }
}