【发布时间】:2016-06-02 07:52:42
【问题描述】:
我有控制台应用程序,我创建类 然后我创建一些函数并在程序类中调用该函数
一个是
public class student
{
public string Lastname { get; set; }
public List<int> scores { get; set; }
}
public void example2
{
List<student> std = new List<student>
{
new student {Lastname="ALI",scores=new List<int>{97, 72, 81, 60}},
new student{Lastname="abc",scores=new List<int>{75, 84, 91, 39}},
new student {Lastname="shan",scores=new List<int>{12,34,6,23,434}},
new student{Lastname="ahmad",scores=new List<int>{34,23,45,34}}
};
var sq = from stud in std
from scor in stud.scores
where scor > 90
select new { last = stud.Lastname, scor };
Console.WriteLine("Scorequery");
foreach (var stdquery in sq)
{
Console.WriteLine("{0}Score:{1}", stdquery.last, stdquery.scor);
}
Console.WriteLine("Exit");
Console.ReadLine();
}
另一个例子
public void example2
{
int[] numbers = { 0, 1, 2, 3, 4, 5, 6 };
var q1 = from q2 in numbers
where q2 < 5
select q2;
foreach (int i in q1)
{
Console.WriteLine(i + "");
}
Console.ReadLine();
}
现在 int[] 上发生错误是
需要一个 get 或 set 访问器
我在哪里创建公开
与另一个函数相同,并且在此行发生错误
List<student> std = new List<student>
以及这一行的另一个函数
char[] uppercase = { 'A', 'B', 'C' };
【问题讨论】:
-
我不知道这是否只是将代码放在那里时的拼写错误,但是 example2 方法声明都没有括号。它们应该如下所示: public void example2 () not public void example2