Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How can I define type variant in c#?

Reply
Thread Tools

How can I define type variant in c#?

 
 
rkbnair
Guest
Posts: n/a
 
      01-07-2008
How can I define type variant in c#?
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      01-07-2008
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#?

 
Reply With Quote
 
 
 
 
rkbnair
Guest
Posts: n/a
 
      01-07-2008
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#?

 
Reply With Quote
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      01-07-2008
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#?

 
Reply With Quote
 
rkbnair
Guest
Posts: n/a
 
      01-07-2008
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#?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
#define ALLOCIT(Type) ((Type*) malloc (sizeof (Type))) Yevgen Muntyan C Programming 10 02-13-2007 02:52 AM
Sharing code for a variant style type christopher diggins C++ 3 01-05-2005 08:34 PM
type VARIANT and array - conversion to CString romi C Programming 2 09-02-2004 12:58 PM
type VARIANT and array - conversion to CString romi C++ 1 09-02-2004 10:52 AM



Advertisments