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

undefined value how?

I am used to initilize vars with Null to mean undefined, but in c#
even complex types such as DateTime are considered value-types
so they cant be null. So far I have worked around the problem
using values that are outside the normal working range of my
programs or some other workaround, but in many places it turns
my code into an obscure piece of sh*t code! It make the code look
old fashion C, and not very nice to hand over to some other programmer
for maintainance. Anyone has a solution? - my books mention nothing of
this issue so its probably so simple it staring me stright in the face.
Nov 16 '05 #1
3 2240
TDOR,

It's not a matter of DateTime being a complex type (which I don't know
what you mean by that), but rather, it is a value type, and value types can
not be null.

In the new version of .NET, there will be a structure introduced called
Nullable<T>, which is a generic. It will have a HasValue property, which if
true, means that the Value property returns a value. If it is false, then
the value is considered to be null.

Also, there will be new syntax in the language to handle this.
Basically, to have a nullable of any value type, you add ? after the type,
like so:

// Declare a nullable integer type.
int? pintNullableInt = null;

In this case, pintNullableInt.HasValue will return false. If you have
the community preview of VS.NET 2005, you can try it now.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"TDOR" <tj*****@hotmail.com> wrote in message
news:12**************************@posting.google.c om...
I am used to initilize vars with Null to mean undefined, but in c#
even complex types such as DateTime are considered value-types
so they cant be null. So far I have worked around the problem
using values that are outside the normal working range of my
programs or some other workaround, but in many places it turns
my code into an obscure piece of sh*t code! It make the code look
old fashion C, and not very nice to hand over to some other programmer
for maintainance. Anyone has a solution? - my books mention nothing of
this issue so its probably so simple it staring me stright in the face.

Nov 16 '05 #2
Hi,

Teh only type I can think of with this problem is DateTime , but I'm sure
there are others, the solution is either wrap it on a custom type that does
support a "null" value or just assume that a value does that function,
DateTime.MinValue for example

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"TDOR" <tj*****@hotmail.com> wrote in message
news:12**************************@posting.google.c om...
I am used to initilize vars with Null to mean undefined, but in c#
even complex types such as DateTime are considered value-types
so they cant be null. So far I have worked around the problem
using values that are outside the normal working range of my
programs or some other workaround, but in many places it turns
my code into an obscure piece of sh*t code! It make the code look
old fashion C, and not very nice to hand over to some other programmer
for maintainance. Anyone has a solution? - my books mention nothing of
this issue so its probably so simple it staring me stright in the face.

Nov 16 '05 #3
We solved this problem in our app using a wrapper class. this way the date
could be null since the wrapper is a class.

--
cody

[Freeware, Games and Humor]
www.deutronium.de.vu || www.deutronium.tk
Nov 16 '05 #4

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

Similar topics

1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
13
by: -Lost | last post by:
You can test for an undefined value in two ways: function blah(x) { if (x == undefined) { x = 'default value'; } } That could also have been written: function blah(x)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.