Home > database >  Why does all members of a class show error 'CS0103'
Why does all members of a class show error 'CS0103'

Time:10-25

I'm testing a piece of code in c# and vs2022, but I encounter some problems. I try to track the value of some members in a class, but the VS2022 shows error CS0103. So I would like to know why VS2022 can't show their values because they are certainly in this context.

class Program
{

    static void Main(string[] args)
    {
        ProtoType p = new ProtoType(100, 200);

        p.x = 101;
        p.y = 20;
        int cnt = p.list.Count;
        Console.ReadLine();
    }
}

class ProtoType
{
    public int x = 0;
    public int y = 0;
    public List<string> list = new List<string>();

    public ProtoType(int x, int y)
    {

        Console.WriteLine("Execute Constructor ProtoType()");
        this.x = x;
        this.y = y;
    }

    public ProtoType Clone()
    {
        Console.WriteLine("Execute ProtoType.Clone()");
        return (ProtoType)this.MemberwiseClone();
    }
}

enter image description here

CodePudding user response:

Because x, y and list are not variables in this scope. they are members of the class ProtoType. you need to watch for p.x, p.y and p.list in place of the x, y, list.

  • Related