就这么一个小例子,大家帮帮忙using System;namespace delme
{
public class Pdtype 
{
public float  x;
public Pdtype next;
}; class Class1
{
float find_x(Pdtype pd, int num)
{
Pdtype pdtemp;
int i;
pdtemp=pd;
for (i=1; i<num; i++)
pdtemp=pdtemp.next;
return (pdtemp.x);
} static void Main(string[] args)
{
Pdtype pdh;
float f=find_x(pdh, 5);
Console.Write(f);
}
}
}

解决方案 »

  1.   

    我不知道你代码的意思,但是按照以下的方法写就可以运行了。更改的地方后面有记号。
    using System;namespace ConsoleApplication2
    {
    public class Pdtype 
    {
    public float  x;
    public Pdtype next;
    }; class Class1
    {
    static float find_x(Pdtype pd, int num) //更改
    {
    Pdtype pdtemp;
    int i;
    pdtemp=pd;
    for (i=1; i<num; i++)
    pdtemp=pdtemp.next;
    return (pdtemp.x);
    } static void Main(string[] args)
    {
    Pdtype pdh = new Pdtype (); //更改
    pdh.x = 1;  //更改
    pdh.next = pdh ;  //更改
    float f=find_x(pdh, 5);
    Console.Write(f);
    }
    }
    }
      

  2.   

    由于CLASS1没有实列,所以不能引用成员float find_x(Pdtype pd, int num)
    解决方法是把函数写成STATIC float find_x(Pdtype pd, int num)