Bob,
Here is a link to a discussion that should show you some sample code.
They got around it by creating a "dummy" class, overloading the operators,
as well as the Equals() and GetHashCode() methods. You have to overload the
2 methods just mentioned if you are going to overload the "==" and "!="
comparison operators.
http://groups.google.com/groups?hl=e...com%26rnum%3D2
The name of the thread is "c# assign null to a struct". If the link above
doesn't work, just search for that thread on google.
--
Lateralus [MCAD]
"Bob Gregory" <bobgregory@ppsltd.net> wrote in message
news:aba9c4c4.0409040703.313da156@posting.google.c om...[color=blue]
> "Lateralus [MCAD]" <dnorm252_at_yahoo.com> wrote in message
> news:<#aTXMUikEHA.3372@TK2MSFTNGP09.phx.gbl>...[color=green]
>> Bob,
>> I suppose you could take a look at overloading operators....but it
>> could
>> get ugly.[/color]
>
>
> That was one of the things I considered, but it did seem a little over
> the top for such a simple operation. Out of curiosity, what is the
> basic syntax for creating an overloaded operator to test for null?
>[color=green]
>>Like I said, this is an alternative, but the easier route would be
>> just to make it a class. Technically a struct is going to be faster than
>> a
>> class, but lets be honest, it's not going to bring your systems memory to
>> it's knees.[/color]
>
> Yeah, I came to this conclusion 5 minutes after posting, with the aid
> of a guide to reference and value types; that's about my average
> whenever I post to Google, so I always end up feeling foolish.
> Conceptually it's nicer anyway because a user is an object and not a
> value, but that's what you get for trying to be clever about
> performance.
>[color=green]
>>
>> HTH
>>[/color]
>
> You confirmed what I'd figured out, and you have letters after your
> name, so thanks a lot :)
>
>
> -- Bob
>
>[color=green]
>> "Bob Gregory" <bobgregory@ppsltd.net> wrote in message
>> news:aba9c4c4.0409031652.7e6ef230@posting.google.c om...[color=darkred]
>> > Hi all, I'm utter C# newbie, do be gentle.
>> >
>> > VS2005 Express refuses point blank to install on my box, so I'm stuck
>> > with C# 1.0 unless someone can point me to a C#2.0 compiler elsewhere.
>> >
>> > I have an authentication system rigged up, which is working, but I'd
>> > like to be able to run a test like this
>> >
>> > <code>
>> >
>> > user thisUser = UserDirectory.GetUserByUsername(Username);
>> > if(thisUser==null){
>> > // user does not exist
>> > }
>> > else{
>> > // do password tests, fetch roles etc.
>> > }
>> >
>> > </code>
>> >
>> > but the conditional fails 'cos I can't compare type user and <null>.
>> >
>> > I've compromised by returning an empty user object and then testing
>> >
>> > <code>
>> >
>> > if(thisUser.username == null){
>> > // etc. etc.
>> > }
>> >
>> > </code>
>> >
>> > which works but /smells/ wrong... is there a better way? Will the
>> > nullable types in C# 2.0 let me do this?
>> >
>> > Cheers for any advice you can offer,
>> >
>> > -- Bob[/color][/color][/color]