Click here to Skip to main content
15,906,816 members
Home / Discussions / C#
   

C#

 
GeneralRe: FileAccess Pin
leppie28-Aug-02 1:53
leppie28-Aug-02 1:53 
GeneralRe: FileAccess Pin
Mazdak28-Aug-02 3:11
Mazdak28-Aug-02 3:11 
General.Net framework source code Pin
27-Aug-02 21:53
suss27-Aug-02 21:53 
Generalfind a string in another string Pin
Mazdak27-Aug-02 20:55
Mazdak27-Aug-02 20:55 
GeneralRe: find a string in another string Pin
Nnamdi Onyeyiri27-Aug-02 21:18
Nnamdi Onyeyiri27-Aug-02 21:18 
GeneralRe: find a string in another string Pin
Mazdak27-Aug-02 22:20
Mazdak27-Aug-02 22:20 
GeneralRe: find a string in another string Pin
Nnamdi Onyeyiri28-Aug-02 2:19
Nnamdi Onyeyiri28-Aug-02 2:19 
QuestionC# and null Structs? Pin
Rodney S. Foley27-Aug-02 18:01
Rodney S. Foley27-Aug-02 18:01 
Why can't you set an instance of a struct to null? And therefore you cannot test a struct for null.

Which if this cannot be done really really sucks big time. I get compiler errors when I try to set an instance of a struct to null or test it for null.

I have checked my 3 C# books, and none of them even talk about it, and none of them never even use the word null in the book even once.

If this is true this is very stupid, it creates more work for some coding solutions.

In case it is important the struct in question is a "System.Drawing.Rectangle".

The errors:
#1: error CS0037: Cannot convert null to 'System.Drawing.Rectangle' because it is a value type

#2: error CS0019: Operator '==' cannot be applied to operands of type 'System.Drawing.Rectangle' and '<null>'

This is one reason I dislike structs.

Thanks,

Aalst

>> UPDATE

I figured a way around this. Setting a instance of a Rectangle to Rectangle.Empty, and then testing with IsEmpty property.

This works, but still doesn't tell me why, just that the implementor was prepared for it.

Anyway... still would like to know why (besides that it is a value type). Why Structs which are so similar to objects, and act like them in so many ways, can not act like them in this way thats all.

Thanks again,

Aalst
AnswerRe: C# and null Structs? Pin
James T. Johnson27-Aug-02 18:18
James T. Johnson27-Aug-02 18:18 
GeneralRe: C# and null Structs? Pin
Rodney S. Foley27-Aug-02 18:47
Rodney S. Foley27-Aug-02 18:47 
GeneralRe: C# and null Structs? Pin
leppie27-Aug-02 21:33
leppie27-Aug-02 21:33 
GeneralRe: C# and null Structs? Pin
Rodney S. Foley28-Aug-02 8:18
Rodney S. Foley28-Aug-02 8:18 
GeneralRe: C# and null Structs? Pin
leppie28-Aug-02 8:52
leppie28-Aug-02 8:52 
AnswerRe: C# and null Structs? Pin
Alastair Stell27-Aug-02 21:52
Alastair Stell27-Aug-02 21:52 
GeneralRe: C# and null Structs? Pin
Rodney S. Foley28-Aug-02 7:50
Rodney S. Foley28-Aug-02 7:50 
GeneralRe: C# and null Structs? Pin
Alastair Stell29-Aug-02 4:48
Alastair Stell29-Aug-02 4:48 
GeneralRe: C# and null Structs? Pin
Rodney S. Foley29-Aug-02 9:49
Rodney S. Foley29-Aug-02 9:49 
GeneralCPropertySheet Pin
candan27-Aug-02 17:11
professionalcandan27-Aug-02 17:11 
GeneralRe: CPropertySheet Pin
James T. Johnson27-Aug-02 17:52
James T. Johnson27-Aug-02 17:52 
GeneralRe: CPropertySheet Pin
candan27-Aug-02 20:06
professionalcandan27-Aug-02 20:06 
GeneralRe: CPropertySheet Pin
James T. Johnson27-Aug-02 20:11
James T. Johnson27-Aug-02 20:11 
GeneralRe: CPropertySheet Pin
leppie27-Aug-02 21:42
leppie27-Aug-02 21:42 
GeneralJames, how do i upload? Pin
leppie27-Aug-02 22:00
leppie27-Aug-02 22:00 
GeneralRe: James, how do i upload? Pin
Mazdak27-Aug-02 22:23
Mazdak27-Aug-02 22:23 
GeneralRe: James, how do i upload? Pin
James T. Johnson28-Aug-02 6:06
James T. Johnson28-Aug-02 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.