日期:2014-05-20 浏览次数:20983 次
例如数组 string[] ids= "3,14,15,19,20".ToString().Split(',');
public List<table> getlist(string[] ids)
{
.......
var list = dc.table.where(a=>a.id.ToString() in ids).ToList();
return list;
}
public class table
{
public int id { get; set; }
public string name { get; set; }
}
static void Main(string[] args)
{
string[] ids = "3,14,15,19,20".ToString().Split(',');
List<table> tc = new List<table> { new table { id = 3, name = "a" }, new table { id = 14, name = "b" }, new table { id = 3, name = "c" } };
List<table> tables = tc.Where(a => ids.Contains(a.id.ToString())).ToList();
tables.ForEach(a => { Console.WriteLine(string.Concat("id=", a.id.ToString())); Console.WriteLine(string.Concat("name=", a.name)); });
Console.Read();
}