如何列出&LT转换;串&GT;列出&LT; INT&GT ;? [英] How to convert List<string> to List<int>?
本文介绍了如何列出&LT转换;串&GT;列出&LT; INT&GT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题是这个问题的一部分:
我收到ID的集合,从一种形式。我需要得到的钥匙,并将其转换为整数,然后从数据库匹配的记录。
[HttpPost]
公众的ActionResult报告(的FormCollection集合)
{
变种listofIDs = collection.AllKeys.ToList();
//列表&LT;串GT;列出&LT; INT&GT;
清单&LT;晚餐及GT;晚餐=新的List&LT;晚餐&GT;();
晚餐= repository.GetDinners(listofIDs);
返回查看(晚餐);
}
解决方案
listofIDs.Select(int.Parse).ToList()
My question is part of this problem:
I recieve a collection of id's from a form. I need to get the keys, convert them to integers and select the matching records from the DB.
[HttpPost]
public ActionResult Report(FormCollection collection)
{
var listofIDs = collection.AllKeys.ToList();
// List<string> to List<int>
List<Dinner> dinners = new List<Dinner>();
dinners= repository.GetDinners(listofIDs);
return View(dinners);
}
解决方案
listofIDs.Select(int.Parse).ToList()
这篇关于如何列出&LT转换;串&GT;列出&LT; INT&GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文