Although delegate type and Enum type are class types, we can not inherit from them as they are sealed classes after compile, public delegate void DelegateTestType(); //Compile time error class myTest : DelegateTestType { ... } we can not make it as a type constraint either on class or method: //Compile time error class myTest<T> where T : DelegateTestType { } From the C# 2.0 specification we can read (20.7, Constraints): A class-type constraint must satisfy the following rules: ยท The type must...
We all know the usage of the anonymous type: var obj = new { Name = "John", Age = 24 }; What if we want to add a anonymous delegate or Lamba to it? Like: var obj = new { Name = "John", Age = 24, behaviour=delegate(string name, int age) { return "Customer Name: " + name + ", Age: " + age; } }; or var obj = new { Name = "John", Age = 24, behaviour = (name, age) => string.Format( "Hello, {0}! You are {1} years old.", name, age ) }; The above two will cause compile time error, because anonymous type...