class Program
{
static void Main(string[] args)
{
dynamic t = new TestClass();
Console.ReadLine();
}
}
public class TestClass
{
public void TestMethod()
{
Console.WriteLine("Dynamic");
}
}
Now if I build the solution, it will be successfully build. In my Main method, I have created an object of 'TestClass' and it's type is dynamic. Now here comes one of the nice thing.
dynamic I |
When I try to call the 'TestMethod', intellisense will show me "This operation will be resolved at run time". It's of course because I have used dynamic. Look at the following image.
dynamic II |
dynamic III |
So the point is, it will only throw you the error in the run time and not in the compile time.
I can write the same using var type. But when using var, the compiler determines the type in compile time. So not like using dynamic, intellisense will show all the available options. And if I use var here instead of dynamic and I try to call the method 'Test', compiler will throw me the error in compile time. So that's something about dynamic.
Happy Coding.
Regards,
Jaliya
No comments:
Post a Comment