我的代码如下:
public class Student
{
private string name;
private int age;
private static int count;
/// <summary>
/// 构造函数
/// </summary> public string Name
{
get { return name; }
set { name = value; }
} public int Age
{
set { age = value; }
}
public int Count
{
get { return count; }
set { count = value; }
} public Student()
{
//
// TODO: 在此处添加构造函数逻辑
//
Student.Count++;
}
}当我申明一个该类的对象student1后,用类调用Student.Count时来查看count变量的值时,提示
错误 1 非静态的字段、方法或属性“Student.Count.get”要求对象引用
请问哪里错了?
public class Student
{
private string name;
private int age;
private static int count;
/// <summary>
/// 构造函数
/// </summary> public string Name
{
get { return name; }
set { name = value; }
} public int Age
{
set { age = value; }
}
public int Count
{
get { return count; }
set { count = value; }
} public Student()
{
//
// TODO: 在此处添加构造函数逻辑
//
Student.Count++;
}
}当我申明一个该类的对象student1后,用类调用Student.Count时来查看count变量的值时,提示
错误 1 非静态的字段、方法或属性“Student.Count.get”要求对象引用
请问哪里错了?
{
get { return count; }
set { count = value; }
}