请问此处的CS0135错误如何解决
问题描述:
RT,对照视频学习C#,但是出现了视频中没有出现的错误
namespace _17
{
class Program
{
static void Main(string[] args)
{
List<student> stuList=new List<student>();
for (int i = 0; i < 10; i++)
{
student stu = new student();
stu.age=24;
stu.score =i;
stuList.Add(stu);
}
int totalAge = 0;
int totalScore = 0;
foreach (var student in stuList)
{
totalAge += student.age;
totalScore += student.score;
}
student.averageAge = totalAge / student.amount;
student.averageScore = totalScore / student.amount;
student.reportAmount();
student.reportAverageAge();
student.reportAverageScore();
}
}
class student
{
public int age;
public int score;
public static int averageAge=0;
public static int averageScore=0;
public static int amount=0;
public student()
{
student.amount++;
}
public static void reportAmount()
{
Console.WriteLine(student.amount);
}
public static void reportAverageAge()
{
Console.WriteLine(student.averageAge);
}
public static void reportAverageScore()
{
Console.WriteLine(student.averageScore);
}
}
}
编译器报错为:
错误 1 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 28 13 17
错误 2 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 28 45 17
错误 3 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 29 13 17
错误 4 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 29 49 17
错误 5 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 30 13 17
错误 6 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 31 13 17
错误 7 “student”与声明“_17.student”冲突 E:\Program Files (x86)\vs2013\工程\17\17\Program.cs 32 13 17
22到26行代码中的“student”有红色波浪线
该错误视频中未出现,
帮助查看器中仅显示了错误代码CS0135,未找到解决方法
求解答,希望能够指出我的代码错误
答
把上面那个foreach里面的个student换个别的变量名,不要跟类名一样
答
this.吧