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

Assigning null value to float or int type variable in C#

Hi to All,
I am Punit Shrivastava .I am working on Asp.net with C#.i am new in C#.I want to assign null or blank to a variable which is of float or int type.Please suggest me what i do.
Thanks & Regards.
Punit Shrivastava.
Nov 13 '07 #1
6 26519
r035198x
13,262 8TB
Hi to All,
I am Punit Shrivastava .I am working on Asp.net with C#.i am new in C#.I want to assign null or blank to a variable which is of float or int type.Please suggest me what i do.
Thanks & Regards.
Punit Shrivastava.
Is the variable a nullable type?
Nov 13 '07 #2
Plater
7,872 Expert 4TB
You cannot specifically asign a valuetype a null value.

Expand|Select|Wrap|Line Numbers
  1. int a;
  2.  
is as close as you can get to a null value for it.

You can use a predefined value:
Expand|Select|Wrap|Line Numbers
  1. int a=int.MinValue;
  2.  
Or just start with a zero:
Expand|Select|Wrap|Line Numbers
  1. int a=0;
  2.  
Nov 13 '07 #3
r035198x
13,262 8TB
You cannot specifically asign a valuetype a null value.
Unless if the value type is a nullable type.
For each non-nullable value type T there is a corresponding nullable type T?, which can hold an additional value null. For instance, int? is a type that can hold any 32 bit integer or the value null.
Nov 13 '07 #4
Plater
7,872 Expert 4TB
Unless if the value type is a nullable type.
ValueTypes aren't nullable, the ValueType? is no longer a ValueType but the other type (can't think of the name, it's what classes are. ObjectType?).
I think that is what the difference between say "double" and "Double" is?
Nov 13 '07 #5
r035198x
13,262 8TB
ValueTypes aren't nullable, the ValueType? is no longer a ValueType but the other type (can't think of the name, it's what classes are. ObjectType?).
I think that is what the difference between say "double" and "Double" is?
Nullable types are value types.
There are four types of value types in C# (Simple types, Enum types, Struct types and Nullable types).
Remember everything is an object. There was no need for making nullable types reference types since their size is always known before hand anyway.
Nov 13 '07 #6
Plater
7,872 Expert 4TB
Perchance I have just been schooled.
Nov 13 '07 #7

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

Similar topics

0
by: Kenny Mullican | last post by:
I am using complex types in order to support serialization/deserialization of floating point numbers, since floating points can't be null. I've seen how to suppress attributes that are "not...
3
by: Robb Gilmore | last post by:
Hello, We have a C#.NET app which is calling a Java webservice. We use the wsdl file exportted from the java webservice to create our web-reference in Visual Studio. We are able to create the...
1
by: George Marsaglia | last post by:
The essence of a multiply-with-carry RNG is to have declarations in the RNG proc, such as unsigned long mwc( ){ static unsigned long x = 123456789, c = 362436; unsigned long long t, a =...
102
by: junky_fellow | last post by:
Can 0x0 be a valid virtual address in the address space of an application ? If it is valid, then the location pointed by a NULL pointer is also valid and application should not receive "SIGSEGV"...
29
by: Jason Curl | last post by:
I've been reading this newsgroup for some time and now I am thoroughly confused over what NULL means. I've read a NULL pointer is zero (or zero typecast as a void pointer), others say it's...
7
by: Adrian Parker | last post by:
'function to convert null to nothing Function CheckDate(ByVal DRow As DataRow, ByVal strCol As String) As Date If DRow.Item(strCol) Is System.DBNull.Value Then Return Nothing Else Return...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
15
by: khan | last post by:
Hi, I read that pointer representation can non-zero bit pattern, machine specific.Compiler when comes accross value '0' in pointer context, converts it to machine specific null pointer...
6
by: cleary1981 | last post by:
I have adapted code from http://dunnbypaul.net/js_mouse/ I want to use a button to create new draggable divs but i keep getting error "is null or not an object" heres the code <html> <head>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.