Click here to Skip to main content
13,297,799 members (48,240 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hello , I just understood that dynamic is unlike the object and can call methods and variables from the instance and not matter which type it is .
I want to know if i can use the dynamic keyword as usual instead of typing the type's name every time which also limiting the pointer for only one type of instances .

Secondly , i want to know much it affects the performance while using a lot of dynamic pointers in my code .

Third question , can i suddenly change the pointed instance of the dynamic pointer to another instance (for example from another dynamic pointer) and it will be quite fast and effective ?

Here some code :
dynamic Instance;
Instance = new Button();
Instance = new Panel();
Instance = 10;

About the 3rd question :
dynamic A = 10;
dynamic B = "string";
B = A;
Console.WriteLine(A + B); // Expected output : 20

Generally i want to know how much using "dynamic" is hurts the performance of my code . Because i am working on really critical class . But i also need the dynamic pointers (if not then the object pointer which are more problematic)
Posted 29-Dec-12 21:15pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

1) First of all, try it!

2) As I see, you mix/confuse var with dynamic. And are speaking pointers. But there are not pointers in c#. Actually there are, but not how you think (see:[^]). So if you really want to use this C/C++ approach, go on, but it will be hard.

3) What do you expect from changing the variable type? You gain nothing at all.

4) Behind the dynamic metatype there is a logic, there is lot of code. That code will take time to execute. This is why you will loose considerable performance when using it this way.

5) Dynamic is more useful in interop situations: Get rid of COM Interop DLL by using the new C# 4 dynamic keyword[^]

.. and more: Adventures with C# 4.0 dynamic - ExpandoObject, ElasticObject, and a Twitter client in 10 minutes[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171207.1 | Last Updated 30 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100