老是提示“非静态的字段、方法或属性“ConsoleApplication9.Class1.squareref(ref int)”要求对象引用“using System;namespace ConsoleApplication9
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
int y = 5;
squareref(ref y); } void squareref(ref int x)
{
x = x * x;
}
}
}

解决方案 »

  1.   

    Class1 c = new Class1();
    c.squareref(ref y);
      
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
      

  2.   

    用:
    static void Main(string[] args)
    {
    int y = 5;
    squareref(out y); } void squareref(out int x)
    {
    x = x * x;
    }
    试试。
      

  3.   

    void squareref(ref int x)前面加个staticstatic void squareref(ref int x)