我需要做类似以下的事情:
public class carros
{
public int id { get; set; }
public string nome { get; set; }
}
public void listar_carros()
{
List<carros> cars = new List<carros>();
cars.Add(new carros{ id= 1, nome = "Fusca" });
cars.Add(new carros{ id= 2, nome = "Gol" });
cars.Add(new carros{ id= 3, nome = "Fiesta" });
var queryResult = from q in cars
where q.nome.ToLower().Contains("eco")
orderby q.nome
select new { q.nome, q.id };
doSomething(queryResult)
}
我需要将queryResult
变量传递给函数doSomething()
。我尝试使用动态类型List<T>
对象,但没有任何效果。
public void doSomething(???? queryResult)
{
foreach (carros ca in queryResult)
{
Response.Write(ca.nome);
Response.Write(" - ");
Response.Write(ca.id);
}
}