0 c# memory oop visual-studio visual-studio-debugging
我正在用c#和vs2022测试一段代码,但遇到一些问题。我尝试跟踪类中某些成员的值,但 VS2022 显示错误 CS0103。所以我想知道为什么VS2022不能表现出他们的价值观,因为他们肯定是在这个背景下。
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();
}
}
Run Code Online (Sandbox Code Playgroud)
因为x、y和list不是此范围内的变量。他们是班级成员ProtoType。您需要注意p.x,p.y并p.list代替 x, y, list。