using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
public class Employee
{
public int ID { get; set; }
public string Name { get; set; }
public Employee()
{
this.Name = "N/A";
this.ID = 0;
}
public static List<Employee> GetEmployees()
{
List<Employee> list = new List<Employee>()
{
new Employee(){ID=1,Name="Raj"},
new Employee(){ID=2,Name="Digvijay"},
new Employee(){ID=3,Name="Ramya"},
new Employee(){ID=4,Name="Ramesh"}
};
return list;
}
}
class Program
{
static void Main(string[] args)
{
Employee obj = new Employee();
foreach (Employee emp in Employee.GetEmployees())
{
Console.WriteLine("Employee ID ={0} , Employee Name ={1}", emp.ID, emp.Name);
}
Console.ReadLine();
}
}
}
Local Variable | Compiler will infer as: |
---|---|
var i = 10; | Int i=10; |
var s = "Hello World"; | String s=”Hello World”; |
var num = new int[ ] {10, 20, 30}; | Int [ ] num = new int [ ] {10, 20, 30}; |
var d = new Dictionary(); | Dictionary d = new Dictionary(); |
var result =
from c in Employee.GetEmployees()
where c.ID == 1
select c;
foreach (var emp in result)
{
Console.WriteLine ("Employee ID = {0} , Employee Name ={1}", emp.ID,
emp.Name);
}