How can I define type variant in c#?

B

bruce barker

use datatype object. you can use the is operator to determine type

void mtProc(object obj)
{
if (obj is int)
...
else if (obj is string)
...
else if (obj is myDatatype)
....
}

to call any methods other than the object generic, you will need to use a
cast.

note: if you are call calling a com routine, object is also the type that is
used for a variant parameter (or return value)

-- bruce (sqlwork.com)
 
R

rkbnair

Thanks. What should I do if I do not know the return type of a class/function
of a certain thirdparty library?

In VB I can say

variant abcd=MyThirdPartyLib.MyThirdPartyLibFunction()

What would be the equivalent in C#?
 
P

Peter Bromberg [C# MVP]

The .NET Framework does not have a "variant" type. If you start typing the
method signature of a referenced third-party library in the Visual Studio
IDE, Visual Studio Intellisense will show you the return type of the method.

Failing that, you can do this:

Object abcd=MyThirdPartyLib.MyThirdPartyLibFunction();

type t = typeof(abcd);

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 
R

rkbnair

That will do it.

Thanks a lot.


Peter Bromberg said:
The .NET Framework does not have a "variant" type. If you start typing the
method signature of a referenced third-party library in the Visual Studio
IDE, Visual Studio Intellisense will show you the return type of the method.

Failing that, you can do this:

Object abcd=MyThirdPartyLib.MyThirdPartyLibFunction();

type t = typeof(abcd);

-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top