我是C#新手,大家帮我看一下错在哪?
using System;class chengji
{
private int[] cj = new int [3];
public int this [string xk]
{
set
{
switch (xk)
{
case "语文":
cj[0] = value;
break;
case "数学":
cj[1] = value;
break;
case "平均分":
cj[2] = value;
break;
}
}
get
{
switch (xk)
{
case "语文":
return cj[0];
case "数学":
return cj[1];
case "平均分":
retrun cj[2];
default:
return 0;
}
}
}
static void Main()
{
chengji scope = new chengji();
scope["语文"] = 98;
scope["数学"] = 100;
scope["平均分"] = (scope["语文"] + scope["数学"]) / 2;
Console.WriteLine(scope["语文"]);
Console.WriteLine(scope["数学"]);
Console.WriteLine(scope["平均分"]);
}
}
using System;class chengji
{
private int[] cj = new int [3];
public int this [string xk]
{
set
{
switch (xk)
{
case "语文":
cj[0] = value;
break;
case "数学":
cj[1] = value;
break;
case "平均分":
cj[2] = value;
break;
}
}
get
{
switch (xk)
{
case "语文":
return cj[0];
case "数学":
return cj[1];
case "平均分":
retrun cj[2];
default:
return 0;
}
}
}
static void Main()
{
chengji scope = new chengji();
scope["语文"] = 98;
scope["数学"] = 100;
scope["平均分"] = (scope["语文"] + scope["数学"]) / 2;
Console.WriteLine(scope["语文"]);
Console.WriteLine(scope["数学"]);
Console.WriteLine(scope["平均分"]);
}
}
-----------
这个写错了,拼写错误,应该是
return cj[2];