473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Variant datatype in c#.net

38
Hi ...

In VB 6.0 if we want to create a variable that can accept any kind of data..then we declare the variable as "variant" datatype.
For ex: Dim x1
so that x1 can accept any data whether its a string,decimal,integer etc

Similarly,can anyone plz suggest me how to create a such variable in c#.net
(i.e. variable with variant datatype)

Thank you so much in Advance
siri
Nov 6 '07 #1
7 5899
r035198x
13,262 8TB
Hi ...

In VB 6.0 if we want to create a variable that can accept any kind of data..then we declare the variable as "variant" datatype.
For ex: Dim x1
so that x1 can accept any data whether its a string,decimal,integer etc

Similarly,can anyone plz suggest me how to create a such variable in c#.net
(i.e. variable with variant datatype)

Thank you so much in Advance
siri

In C# everything is an object(even methods).
That means you can store anything in a variable of type Object.
Nov 6 '07 #2
balabaster
797 Expert 512MB
In C# everything is an object(even methods).
That means you can store anything in a variable of type Object.
Therefore I would assume it's the same in VB.NET...I usually use "object" if I need to store an item of unknown data type. In fact, I always did the same in VB 6.0; I've only ever used the variant datatype for arrays.
Nov 6 '07 #3
r035198x
13,262 8TB
Therefore I would assume it's the same in VB.NET...I usually use "object" if I need to store an item of unknown data type. In fact, I always did the same in VB 6.0; I've only ever used the variant datatype for arrays.
I've never used VB.NET (which I hate even more passonately than C#) so there.
Nov 6 '07 #4
r035198x
13,262 8TB
@OP. Please do not flood the forum with multiple threads on the same topic. It's against the guidelines. I've already deleted two other threads on the same topic. I hope I won't have to do it again.

If you tried any code then post it and tell us the error you got. Don't just say "it didn't work".
Nov 6 '07 #5
Plater
7,872 Expert 4TB
I believe for arrays, you should use one of the System.Collections objects for dynamic usage, or "Array" for non-dynamic usage.
Otherwise Object will work just fine, provided you know what you're doing.
Nov 6 '07 #6
balabaster
797 Expert 512MB
I believe for arrays, you should use one of the System.Collections objects for dynamic usage, or "Array" for non-dynamic usage.
Otherwise Object will work just fine, provided you know what you're doing.
Yeah, these days you do, I was referring back to VB6/VBA. Now it's been replaced with System.Collections, System.Collections.Generics, System.Array, System.String(), System.Byte() etc...I don't think there's really a need for the Variant type any more. I certainly can't think of a direct requirement for it other than backwards compatibility. I haven't used it in quite a while.
Nov 6 '07 #7
r035198x
13,262 8TB
Yeah, these days you do, I was referring back to VB6/VBA. Now it's been replaced with System.Collections, System.Collections.Generics, System.Array, System.String(), System.Byte() etc...I don't think there's really a need for the Variant type any more. I certainly can't think of a direct requirement for it other than backwards compatibility. I haven't used it in quite a while.
The variant type has been banished in VB.NET.
It does not port well with other languages and made VB slower as it would have to determine which type to cast to all the time.

It's all voodoo I tell you ...
Nov 6 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
3
by: Annie | last post by:
I am trying to call a COM object which expects a variant datatype to be passed in to the COM API object. However, I get "<COMObject <unknown>>" and the program fails. Below is my code in Python,...
8
by: MLH | last post by:
If I choose to dim MyDate as Date or MyDate as Variant, what is the most significant difference between the two choices?
8
by: MLH | last post by:
A97 HELP shows the proper syntax for using Nz as Nz(variant) I'm wondering what to expect from potential past misuse I've made. For example, consider the following... Private Sub...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
2
by: SivaprakashShanmugam | last post by:
Hi, I have an Activex control with VARIANT* parameter type. I want to pass an Array from CSharp to that parameter how can i pass it.
2
by: Heike | last post by:
Hello everybody, I have a Problem with C Sharp. I have to use external functions in DLLs. This Functions are written in Visual C++ 6 like this: int (__stdcall *GetGlobalValue) (VARIANT Appl,...
3
by: G Gerard | last post by:
Hello If Variant type is the data type that contains any kind of data type is there a reason why one would not always use Variant when declaring variables? Thanks G Gerard
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.