How can I define type variant in c#?
am 07.01.2008 17:49:07 von rkbnairHow can I define type variant in c#?
How can I define type variant in c#?
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)
"rkbnair" wrote:
> How can I define type variant in c#?
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#?
"bruce barker" wrote:
> 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)
>
>
> "rkbnair" wrote:
>
> > How can I define type variant in c#?
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
"rkbnair" wrote:
> 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#?
>
> "bruce barker" wrote:
>
> > 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)
> >
> >
> > "rkbnair" wrote:
> >
> > > How can I define type variant in c#?
That will do it.
Thanks a lot.
"Peter Bromberg [C# MVP]" wrote:
> 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
>
>
> "rkbnair" wrote:
>
> > 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#?
> >
> > "bruce barker" wrote:
> >
> > > 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)
> > >
> > >
> > > "rkbnair" wrote:
> > >
> > > > How can I define type variant in c#?