What is the difference between Reflection and Dynamic?
- Both reflection and dynamic are used when we want to operate on an object during runtime.
- Reflection is used to inspect meta-data of an object. It also has the ability to invoke members of an object on runtime.
- Dynamic is a keyword which was introduced in .NET 4.0. It evaluates object calls during runtime. So until the method calls are made compiler is least bothered if those methods / properties etc exist or not.
- Dynamic uses reflection internally. It caches the method calls made thus improving performance to a certain extent.
- Reflection can invoke both public and private members of an object while dynamic can only invoke public members.
Below is the detail comparison table which shows in which scenario they are suited.
Below is a simple diagram which summarizes visually what reflection can do and what dynamic keyword can do?.
What is the difference between Convert.toString and .toString () method?
Just to give an understanding of what the above question means seethe below code.
We can convert the integer “i” using “i.ToString()” or “Convert.ToString” so what is the difference. The basic difference between them is “Convert” function handles NULLS while “i.ToString()” does not.It will throw a NULL reference exception error. So as a good coding practice using “convert” is always safe.
See the following video on difference between string and stringbuilder: -
Click and see here for more training in .NET