Guest User

Untitled

a guest
Sep 21st, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace linkTest
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<Thing> listOfThings = new List<Thing>();
  14.             listOfThings.Add(new Thing("thing1","data for thing one"));
  15.             listOfThings.Add(new Thing("thing2", "data for thing two"));
  16.  
  17.             var myFavorite = from stuff in listOfThings
  18.                              where
  19.                                  stuff.Name == "thing1"
  20.                              select new
  21.                              {
  22.                                  stuff.Name,
  23.                                  stuff.Data
  24.                              };
  25.  
  26.             var foo = myFavorite.First();
  27.             if(foo != null)
  28.                 Console.WriteLine(foo);
  29.            
  30.                
  31.             Console.ReadLine();
  32.  
  33.         }
  34.     }
  35.     class Thing
  36.     {
  37.         public string Name { get; set; }
  38.         public string Data { get; set; }
  39.         public Thing(string name,string data)
  40.         {
  41.             this.Name = name;
  42.             this.Data = data;
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment