I have a multithreaded app that is creating a list of strings on a BlockingCollection queue, I want to take that list of strings and convert it to a collection of item objects in one or 2 steps
Is it possible to create a func<> or lamda method to achieve this type of result
public class item
{
public string name { get; set; }
public item(string nam)
{
name = nam;
}
}
IList<string> alist = new string[] { "bob","mary"};
Where you take a Ilist<> or IEnumerable<> of type string and return IList
So for the single item Func<>
Func<string, item> func1 = x => new item(x);
But essetially the signiture would look like
Func<IEnumerable<string>,IList<item>> func2 = x=> x.ForEach(i => func1(i));
Am I trying to put a round peg in sqaure hole or is my syntax/logic just wrong
Thanks in advance
You will have to use a
Selectprojection instead ofForEachand then convert the resultingIEnumerable<item>to a list usingToList()– this should work: