.net 6.0
VSCode
创建了两个类,在一个类中初始化另外一个类的对象并调用其属性或者方法。
报错如下:
Invalid token '=' in class, record, struct, or interface member declaration [Test, Test]csharp(CS1519)
修改如下:
public class Person {
public string name;
public int age;
public void ShowInfo()
{
Console.WriteLine("姓名:{0}, 年龄:{1}", name, age);
}
}
public class Student
{
public static void Main()
{
Person p = new Person();
p.name = "小明";
p.age = 12;
p.ShowInfo();
}
}