PC Review


Reply
Thread Tools Rate Thread

How can I define type variant in c#?

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

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
MIDL VARIANT-type to proper C# type Bjoern Microsoft C# .NET 2 26th Sep 2007 09:58 PM
type VARIANT in C# Martin Microsoft C# .NET 3 18th Apr 2005 06:39 AM
variant array-define, usage,help! Shivalee Gupta via AccessMonster.com Microsoft Access Form Coding 1 1st Feb 2005 01:25 PM
how do I define 'save as type', there are no file type options in. =?Utf-8?B?VGFmZnk=?= Microsoft Outlook Discussion 2 17th Nov 2004 05:21 PM
How to define a Range with variant? Yiu Choi Fan Microsoft Excel Programming 6 12th Jul 2004 04:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:46 PM.