daily pastebin goal
17%
SHARE
TWEET

Untitled

a guest Aug 10th, 2018 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dynamic Constructor using Lambda and Func<>
  2. public class item
  3. {
  4.     public string name { get; set; }
  5.  
  6.     public item(string nam)
  7.     {
  8.         name = nam;
  9.     }
  10.  
  11.  
  12. }
  13.  
  14. IList<string> alist = new string[] {  "bob","mary"};
  15.    
  16. Func<string, item> func1 = x => new item(x);
  17.    
  18. Func<IEnumerable<string>,IList<item>> func2 = x=> x.ForEach(i => func1(i));
  19.    
  20. Func<IEnumerable<string>,IList<item>> func2 = x => x.Select( i => new item(i)).ToList();
  21.    
  22. IList<string> listOfStrings = new string[] {  "bob","mary"};
  23. IList<item> listOfItems = listOfStrings.Select(s => new item(s)).ToList();
  24.    
  25. IEnumerable<item> myfunc(IEnumerable<string> stringlist)
  26. {
  27.     var q = from s in stringlist
  28.             select new item(s);
  29.     return q.ToList();
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top