public float mul(float x,float y)
{
          

    float z=x*y;
return (z);
}
public static void Main()
{
 
float x,y,z; Console.WriteLine("x,y:\n");
Console.ReadLine();
z=mul(x,y);
Console.WriteLine("the result is z={0}",z);
}
c:\inetpub\wwwroot\c\a4.cs(27): c:\inetpub\wwwroot\c\a4.cs(27): 非静态的字段、方法或属性“c.a4.mul(float, float)”要求对象引用??
z=mul(x,y);

解决方案 »

  1.   

    这样就可以了:
            public static float mul(float x, float y)
            {
                float z = x * y;
                return (z);
            }
            public static void Main()
            {            float x, y, z;            Console.WriteLine("x,y:\n");
                Console.ReadLine();
                z = mul(x, y);
                Console.WriteLine("the result is z={0}", z);
            }
      

  2.   

    如果你要static Main方法中调用非静态的mul方法,那么你要实例化该类
      

  3.   

    public static float mul(float x,float y)这
    可是 z=mul(x,y);测试时提示便用了未赋值的局部变量x,y
      

  4.   

    那是当然的,你只是声明了变量x和y,没有赋值,在调用z=mul(x,y);你得先赋值:
    如下:
    float x=0,y=0,z;
      

  5.   

    使用了未赋值的局部变量x,y
    z=mul(x,y);
      

  6.   

    public static float mul(float x, float y)
            {
                float z = x * y;
                return (z);
            }
            public static void Main()
            {            float x = 2, y = 5, z;            Console.WriteLine("x,y:\n");
                Console.ReadLine();
                z = mul(x, y);
                Console.WriteLine("the result is z={0}", z);
            }