Step 1
Create a console application and paste this code in the Program.cs namespace.public class MyClass {
public static string GetID(dynamic d) {
return d.ID;
}
}
class Program {
static void Main(string [] args) {
var o = new { ID = "123" };
Console.WriteLine(MyClass.GetID(o));
Console.ReadLine();
}
}
Run the application. The application displays 123.
Step 2
Add a new class library project, move the class MyClass in the library. Reference the library. Run the application. An exception will be raise by the line "return d.ID;".Explain why ?

No comments:
Post a Comment