
justinlinqexample
By: a guest on
Aug 19th, 2012 | syntax:
C# | size: 1.20 KB | hits: 28 | expires: Never
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace linkTest
{
class Program
{
static void Main(string[] args)
{
List<Thing> listOfThings = new List<Thing>();
listOfThings.Add(new Thing("thing1","data for thing one"));
listOfThings.Add(new Thing("thing2", "data for thing two"));
var myFavorite = from stuff in listOfThings
where
stuff.Name == "thing1"
select new
{
stuff.Name,
stuff.Data
};
var foo = myFavorite.First();
if(foo != null)
Console.WriteLine(foo);
Console.ReadLine();
}
}
class Thing
{
public string Name { get; set; }
public string Data { get; set; }
public Thing(string name,string data)
{
this.Name = name;
this.Data = data;
}
}
}