Developer, Former MVP, now at Microsoft - Best of 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
var results = from p in Process.GetProcesses() where p.Threads.Count > 6 select new {p.ProcessName, ThreadCount = p.Threads.Count, p.Id };
Dim results = _ From p In Process.GetProcesses() _ Where p.Threads.Count > 6 _ Select New With {p.ProcessName, .ThreadCount = p.Threads.Count, p.Id}
var results = Process.GetProcesses() .Where(p => p.Threads.Count > 6) .Select(p=>new {p.ProcessName, ThreadCount = p.Threads.Count, p.Id });
Dim results = _ Process.GetProcesses() _ .Where(Function(p) p.Threads.Count > 6) _ .Select(Function(p) New With {p.ProcessName, .ThreadCount = p.Threads.Count, p.Id})
foreach (var o in results) { Console.WriteLine(o.ToString()); }
private class MothAnonymousType { public string ProcessName; public int ThreadCount; public int Id;// public override string ToString() { return "{ ProcessName = " + ProcessName + ", ThreadCount = " + ThreadCount + ", Id = " + Id + " }"; } } private static bool MothWhere(Process p) { return p.Threads.Count > 6; } private static MothAnonymousType MothSelect(Process p) { MothAnonymousType type1 = new MothAnonymousType(); type1.ProcessName = p.ProcessName; type1.ThreadCount = p.Threads.Count; type1.Id = p.Id; return type1; }
static void Main(string[] args) { IEnumerable<MothAnonymousType> results = Enumerable.Select( Enumerable.Where(Process.GetProcesses(), new Func<Process, bool>(MothWhere)), new Func<Process, MothAnonymousType>(MothSelect)); // foreach (MothAnonymousType o in results) { Console.WriteLine(o.ToString()); } Console.ReadLine(); }