Skip to content

Instantly share code, notes, and snippets.

@sometowngeek
Last active February 24, 2018 18:34
Show Gist options
  • Save sometowngeek/4f419e56c86c986fe5e5d7535f360118 to your computer and use it in GitHub Desktop.
Save sometowngeek/4f419e56c86c986fe5e5d7535f360118 to your computer and use it in GitHub Desktop.
LINQ Example
public class LinqExample
{
public static void Main(String[] args)
{
List<SomeMap> mapList = new List<SomeMap>();
mapList.Add(new SomeMap(1, "Main Office"));
mapList.Add(new SomeMap(2, "Bedroom"));
mapList.Add(new SomeMap(3, "Art Room"));
var result = mapList
.Where(m => m.Name.Contains("Art"))
.Select(c => c.Name)
.ToList();
foreach (var i in result)
{
Console.WriteLine(i);
}
Console.ReadKey();
}
}
public class SomeMap
{
public int Id { get; set; }
public string Name { get; set; }
public SomeMap(int id, string name)
{
this.Id = id;
this.Name = name;
}
public SomeMap()
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment