473,394 Members | 1,817 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,394 software developers and data experts.

type VARIANT in C#

Hi,
I'm a beginner.

Is there type VARIANT in C#?

I use my class dbTextbox (which inherited from Textbox) to store and display
diferent values type from database. Therefore I want to create property
VALUE, which can have dif value types. How can I do this? Is there any idea?

Thanks for help
Martin
Nov 17 '05 #1
3 10445
Martin <ma******@freenet.de> wrote:
Is there type VARIANT in C#?
No, but there is "object", which all types derive from eventually (sort
of, anyway- value types themselves don't derive from anything, but
their boxed equivalents do).
I use my class dbTextbox (which inherited from Textbox) to store and
display diferent values type from database. Therefore I want to
create property VALUE, which can have dif value types. How can I do
this? Is there any idea?


You can certainly declare it to return object.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #2
I can't understand you well.
I does, what you wrote. My DBTextbox class:
public class dbText : System.Windows.Forms.TextBox
public object Value
{
get
{
return base.Text;
}
set
{
base.Text = value.ToString();
}

}

in a function of a form, I try to get value of the dbTextbox, which should be float, but I can't.
private void button1_Click(object sender, System.EventArgs e)
{
float sngValue = 1.234f;
dbtextbox1.Value = sngValue;
dbText2.Value = dbtextbox1.Value;
sngValue =(float) dbText2.Value.ToString() ;
}

How can I do this?

Thanks
Martin

"Jon Skeet [C# MVP]" <sk***@pobox.com> schrieb im Newsbeitrag news:MP************************@msnews.microsoft.c om...
Martin <ma******@freenet.de> wrote:
Is there type VARIANT in C#?


No, but there is "object", which all types derive from eventually (sort
of, anyway- value types themselves don't derive from anything, but
their boxed equivalents do).
I use my class dbTextbox (which inherited from Textbox) to store and
display diferent values type from database. Therefore I want to
create property VALUE, which can have dif value types. How can I do
this? Is there any idea?


You can certainly declare it to return object.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #3
Martin <ma******@freenet.de> wrote:
I can't understand you well.
I does, what you wrote. My DBTextbox class:
public class dbText : System.Windows.Forms.TextBox
public object Value
{
get
{
return base.Text;
}
set
{
base.Text = value.ToString();
}

}

in a function of a form, I try to get value of the dbTextbox, which
should be float, but I can't.
private void button1_Click(object sender, System.EventArgs e)
{
float sngValue = 1.234f;
dbtextbox1.Value = sngValue;
dbText2.Value = dbtextbox1.Value;
sngValue =(float) dbText2.Value.ToString() ;
}


Well, you're *actually* always returning a string at the moment. If you
want to be able to cast to float, you need to return a float. Instead
of just changing the Text property's value, you could have another
member variable which stored the value which was actually set, and
return that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vilmar Brazão de Oliveira | last post by:
HI, How verify MIME type of file?? Which components should I use? Still now I couldn't find anything! OBS.: I don´t to check file extensions! Thanks,
3
by: Vinodh Kumar P | last post by:
Whenever I read any C++ literature I find the words "C++ is statically type checked".OK.Agreed. Is there any language that supports "Dynamic type checking"? In such a case any type can be assigned...
4
by: Claus77 | last post by:
Hi there, I've got a little problem with the following: I'm just writing a com-application in C++ with VS-6, which should also be used with VB-Script, so I have to use variables of type...
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
1
by: darrenbenn | last post by:
I need to convert this code to VB .NET (2003). Dim FaxMsg As IFaxMessage Set FaxMsg = gFC.NewMessage Dim Recip As Variant ' add a recipient to the fax recipients collection Set Recip =...
1
by: G Gerard | last post by:
Hello I am creating a wizard so a user can import data from other type of databases (DBase IV, Paradox etc...) into an Access mdb. The first step would require the user to choose the type and...
3
by: empire5 | last post by:
I'm trying to convert a MS-Sql 6.5 VB application to SQL 2005 and vb.net. The vb app has uses a variant data type. When I try to read the variant data type from the sql 2005 database I get 8,000...
1
by: Coll | last post by:
I have a function that calculates a period of time e.g. 2.3 years, .5 years etc. I was using the function in a query, but since I had not declared a data type for the function, it wasn't sorting...
1
by: captainc | last post by:
I have C++ code to import a .tlb and use a .dll that has functions that return VARIANT types and accepts BSTRs (bstrings). I have seen that python has modules that can manipulate VARIANTs and BSTRs...
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.