|
| 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
|
|
|
| |
|
|
| |
| |
| 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.
|
|
|
| |
|
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|