using System.Collections.Generic;
using System.Linq.Expressions;
public static void Main()
Console.WriteLine("****************** C# Equivalent Output **************************\n\n");
Employee e = new Employee()
Console.WriteLine("Name {0}, DOB {1}",e.Name, e.BirthDate);
Console.WriteLine("\n\n***************** Expression Tree Output **************************\n\n");
Expression testExpr = Expression.MemberInit(
Expression.New(typeof(Employee)),
new List<MemberBinding>() {
Expression.Bind(typeof(Employee).GetMember("Name")[0], Expression.Constant("John")),
Expression.Bind(typeof(Employee).GetMember("BirthDate")[0], Expression.Constant(DateTime.Now))
var emp = Expression.Lambda<Func<Employee>>(testExpr).Compile()();
Console.WriteLine("Name {0}, DOB {1}",emp.Name, emp.BirthDate);
public string Name { get; set; }
public DateTime BirthDate { get; set; }