我有一个多线程应用程序,它在 BlockingCollection 队列上创建一个字符串列表,我想获取该字符串列表并通过一个或两个步骤将其转换为项目对象的集合
是否可以创建一个 func<> 或 lamda 方法来实现这种类型的结果
public class item
{
public string name { get; set; }
public item(string nam)
{
name = nam;
}
}
IList<string> alist = new string[] { "bob","mary"};
从哪里获取 Ilist<> 或 IEnumerable<> 类型的字符串并返回 IList
所以对于单项Func<>
Func<string, item> func1 = x => new item(x);
但基本上签名看起来像
Func<IEnumerable<string>,IList<item>> func2 = x=> x.ForEach(i => func1(i));
我是想在方形孔中放一个圆钉还是我的语法/逻辑错了
提前致谢
最佳答案
你只是想“ reshape ” IList<string>
作为IList<item>
?
IList<string> listOfStrings = new string[] { "bob","mary"};
IList<item> listOfItems = listOfStrings.Select(s => new item(s)).ToList();
关于c# - 使用 Lambda 和 Func<> 的动态构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8450236/