Anonymous Types : var « LINQ « C# / C Sharp






Anonymous Types

 

using System;
using System.Collections.Generic;
using System.Diagnostics;

class MainClass{
    static void DisplayProcesses(Func<Process, Boolean> match) {
        var processes = new List<Object>();
        foreach (var process in Process.GetProcesses()) {
            if (match(process)) {
                processes.Add(new {
                    process.Id, Name = process.ProcessName,
                    Memory = process.WorkingSet64
                });
            }
        }
    }

    static void Main(string[] args) {
        DisplayProcesses(process => process.WorkingSet64 >= 20 * 1024 * 1024);
    }
}

 








Related examples in the same category

1.Using var
2.An Anonymous Type Assigned to a Variable Declared with the var Keyword
3.Instantiating and Initializing an Anonymous Type Using Object Initialization
4.An Example of Collection Initialization