How can I define type variant in c#?

Discussion in 'ASP .Net' started by rkbnair, Jan 7, 2008.

  1. rkbnair

    rkbnair Guest

    How can I define type variant in c#?
     
    rkbnair, Jan 7, 2008
    #1
    1. Advertising

  2. rkbnair

    bruce barker Guest

    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#?
     
    bruce barker, Jan 7, 2008
    #2
    1. Advertising

  3. rkbnair

    rkbnair Guest

    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#?
     
    rkbnair, Jan 7, 2008
    #3
  4. 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#?
     
    Peter Bromberg [C# MVP], Jan 7, 2008
    #4
  5. rkbnair

    rkbnair Guest

    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#?
     
    rkbnair, Jan 7, 2008
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. romi
    Replies:
    1
    Views:
    2,624
    Alf P. Steinbach
    Sep 2, 2004
  2. christopher diggins

    Sharing code for a variant style type

    christopher diggins, Jan 4, 2005, in forum: C++
    Replies:
    3
    Views:
    490
  3. romi
    Replies:
    2
    Views:
    665
    Joona I Palaste
    Sep 2, 2004
  4. Yevgen Muntyan

    #define ALLOCIT(Type) ((Type*) malloc (sizeof (Type)))

    Yevgen Muntyan, Feb 9, 2007, in forum: C Programming
    Replies:
    10
    Views:
    950
    Yevgen Muntyan
    Feb 13, 2007
  5. C++

    Variant return type

    C++, Nov 27, 2005, in forum: C++
    Replies:
    3
    Views:
    434
Loading...

Share This Page