473,396 Members | 2,147 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,396 software developers and data experts.

more about nullable types where the Value property is used

Hello!

What purpose has this Value propery on nullable types because it possible
to display their value without using it.
For example:

int? intNullable1 = 3;
int? intNullable2 = 5;
Console.WriteLine(result); // This display 8
Console.WriteLine(result.Value); // This also display 8 the same

So I can't see any point in using this Value property on nullable types or
have I missed something here perhaps
that makes the Value property useful to have?

//Tony


Jun 27 '08 #1
2 1166
Tony Johansson wrote:
Hello!

What purpose has this Value propery on nullable types because it possible
to display their value without using it.
For example:

int? intNullable1 = 3;
int? intNullable2 = 5;
Console.WriteLine(result); // This display 8
Console.WriteLine(result.Value); // This also display 8 the same

So I can't see any point in using this Value property on nullable types or
have I missed something here perhaps
that makes the Value property useful to have?

//Tony

try this:

public void Test(Int32 value)
{
}

Test(intNullable1);
Test(intNullable1.Value);

--
Lasse Vågsæther Karlsen
mailto:la***@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Jun 27 '08 #2
The code:

Console.WriteLine(result);

Is calling the "ToString()" method on the "result" variable. So its
equivalent of you saying:

Console.WriteLine(result.ToString());

Now, if you look at the internal implementation of the "ToString()" method
on the "Nullable" variable type (using Reflector) is implemented the
following way:

public override string ToString()
{
if (!this.HasValue)
{
return "";
}
return this.value.ToString();
}

So as you can see, you were calling the "Value" property, you just didn't
know you were doing it.

"Tony Johansson" <jo*****************@telia.comwrote in message
news:gl**************@newsb.telia.net...
Hello!

What purpose has this Value propery on nullable types because it possible
to display their value without using it.
For example:

int? intNullable1 = 3;
int? intNullable2 = 5;
Console.WriteLine(result); // This display 8
Console.WriteLine(result.Value); // This also display 8 the same

So I can't see any point in using this Value property on nullable types or
have I missed something here perhaps
that makes the Value property useful to have?

//Tony

Jun 27 '08 #3

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

Similar topics

6
by: Steven Livingstone | last post by:
Bit of advice here folks. I am creating a default constructor that just initializes a new instance of my object and a secon constructor that takes an ID and loads an object with data from the...
3
by: Nemisis | last post by:
Hi everyone, i have been stressing over this for the past hour or so, and just cannot figure it out, sorry if i am being stupid, but it is a friday! lol I have the following Private _ID as...
2
by: Benton | last post by:
Hi there, I'm creating a custom server control, inheriting from TextBox. It has this AsDateTime property that returns the textbox contents converted to the nullable DateTime data type, as...
6
by: Tony Johansson | last post by:
Hello! I'm reading in a book called Visual C# 2005. In the chapter about Generics there ia a section about Nullable types. Here is the text that isn't complete true I think. It says: "You...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.