Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
VB Variant Equivalent in C#
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.vb.


Marcus Kellermann
GOOD ANSWER
I have a COM object in which one of the methods returns an ARRAY of type
VARIANT. (Basically an array of strings). From what I have found VARIANT
is SYSTEM.OBJECT in C#. But I don't understand how to use it? Any
idea/references Haven't really found anything in .NET help files..

-Marcus Kellerman

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
    
Richard Childress
GOOD ANSWER
"Marcus Kellermann" <Click here to reveal e-mail address> wrote in message
news:eQ1sWGJSBHA.1476@tkmsftngp04...
[Original message clipped]

A Variant is not necessarily the same thing as System.Object.

A Variant is a variable that can contain any type of data. The type of the
data is also stored in the Variant.

If my Variant contains "foo", it contains the string "foo" and also type
information indicating that a string is stored.

The .NET type system is slightly different. All types in the .NET framework
inherit from System.Object. This includes 'primitive' types. (e.g.
Integers), (stack vs. heap allocation is dealt with by something called
boxing and unboxing which I won't get into). Anyway, since all types
inherit from System.Object, any variable can be stored in an Object
variable.
So the two are the same, but not. ;)

You should be able to just declare a variable as a string array :

Dim str() as String

Then capture the return value :

str = objMyObject.MyMethod()

And str should contain your array of strings.

Hope this helps.

Reply to this message...
Vote that this is a GOOD answer... (1 vote from another user already)
 
 
 
System.Object




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734