|
| Custom object for undefined values |
 |
Wed, 2 Apr 2008 15:24:27 +0000 |
Hi!
i'm not really sure if this is the topic for this forum but...let's give it a
try ;)
I want to make a public class for undefined values. So, what do I mean by that
huh? For example, when I set values for some object in constructor, I would like
to assign undefined value let's say for integer. Something like: Undefined.Int
(where the value would be I don't know, -274356238?). Something like bulit in
string.Empty thing...
Can someone sets me in the right direction, I need some clues. I don't want
enumerator. I want to access this class from wherever (Page, CodeBehind,
business logic layer, DAL...)
Thanks!
|
| Post Reply
|
| Re: Custom object for undefined values |
 |
Wed, 2 Apr 2008 15:47:26 +0000 |
How about using nullable values?
int? i = null;
if (i.HasValue)
{
// i has non-default value
}
else
{
// i has no value; i == null evals to true
}
|
| Post Reply
|
| Re: Custom object for undefined values |
 |
Thu, 3 Apr 2008 00:08:15 +0000 |
"Matic" wrote in message news:2272063@forums.asp.net...
Hi!
i'm not really sure if this is the topic for this forum but...let's give it a
try ;)
I want to make a public class for undefined values. So, what do I mean by that
huh? For example, when I set values for some object in constructor, I would like
to assign undefined value let's say for integer. Something like: Undefined.Int
(where the value would be I don't know, -274356238?). Something like bulit in
string.Empty thing...
Can someone sets me in the right direction, I need some clues. I don't want
enumerator. I want to access this class from wherever (Page, CodeBehind,
business logic layer, DAL...)
Thanks!
http://forums.asp.net/p/1242158/2272063.aspx#2272063
You could use Nullables. I often use MinValue, but if you wanted your own values
(for value types), something like: public static class DefaultValues { public
static readonly int Int = -274356238; public static readonly string String =
"NULL"'; // not actually a value type, but since it's immutable, we
can treat it as one public static readonly DateTime DateTime = new DateTime(1,
1, 1900);} should do the trick.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|