Vishwakant Tripathi

Vishwakant Tripathi

  • 1k
  • 721
  • 839.1k

Dynamic Type variable in c#

Oct 1 2013 2:24 AM
Hi,
                var obj=new String();

here obj is an object of String Type. But In a case, if we need to create an object dynamically, and even sure about Type, so how we can make it.

For example :-

                  var obj=new DynamicType();   //it's an example only, there is no any Type available in .Net like DynamicType

Here DynamicType is a Type that can be of any .net Type, it may be Int, String, float or any one.

Actually why I need this:-

I am creating a dynamic sql Update query, in which, I need to pass parameter arguments, and number of parameters are not fixed, so I have to create it dynamically, so for String type variable (like varchar, text, char etc), it need Single Quote and for Numeric Type (like int, float, money), no need to single quote.

So all of you, please share your ideas regarding above scenario, if i need to choose any other way or how I can make it possible.

Thanks,
Vishwakant

Answers (7)