【发布时间】:2014-05-04 18:47:10
【问题描述】:
如何使用 C# 和 Asp.net 中的 Linq 从数组中获取所有模块,如下面的学生名字。这可能很容易做到,但未能成功。请帮忙。谢谢。
ArrayList arrList = new ArrayList(); //new array list for students
arrList.Add(
new Student
{
FirstName = "Svetlana",
LastName = "Omelchenko",
Password = "hh",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Claire",
LastName = "O’Donnell",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Sven",
LastName = "Mortensen",
modules = new string[] { "001", "002", "003", "004" }
});
arrList.Add(
new Student
{
FirstName = "Cesar",
LastName = "Garcia",
modules = new string[] { "HH", "KK", "LL", "OO" }
});
var query = from Student student in arrList
where student.FirstName == "Cesar"
select query;
GridView1.DataSource = query;
GridView1.DataBind();
我想将结果放在 Asp.net 中的网格表中。请帮忙!!
【问题讨论】:
-
嗨,谢谢大家的回复,也许我的问题一开始并不清楚,我只想获取字符串数组中的模块,例如 Firstname = "cesar"。在网格视图中,我只想要与该用户名相关的模块。类似于:var query = from Student student in arrList where student.FirstName == "Cesar" select Student.modules;