473,385 Members | 1,344 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,385 software developers and data experts.

Rectangle = null?

Dom
Why can't I say the following;

Rectangle r = null;

The compiler tells me that null is a value type and can't be converted
to Rectangle. But I can't generally set any reference type to null.
For example, I can say:

MyClass c = null;

Aug 13 '07 #1
4 8807
Dom,

I think you mean that you can generally set any reference type to null
(you said can't). This is true, you can assign null to reference type
variables.

However, in this case, the compiler is telling you the truth. Rectangle
is a value type, not a reference type, and you can't assign null to it
(assuming that this is the Rectangle structure from the System.Drawing
namepspace).

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

"Dom" <do********@gmail.comwrote in message
news:11**********************@k79g2000hse.googlegr oups.com...
Why can't I say the following;

Rectangle r = null;

The compiler tells me that null is a value type and can't be converted
to Rectangle. But I can't generally set any reference type to null.
For example, I can say:

MyClass c = null;

Aug 13 '07 #2
On Aug 13, 4:57 pm, Dom <dolivas...@gmail.comwrote:
Why can't I say the following;

Rectangle r = null;

The compiler tells me that null is a value type and can't be converted
to Rectangle. But I can't generally set any reference type to null.
For example, I can say:

MyClass c = null;
A Rectangle is not a class it is a structure and so you can not assign
a null value to it. You should use instead.

Rectangle c = Rectangle.Empty;

Aug 13 '07 #3
Dom
On Aug 13, 11:57 am, Dom <dolivas...@gmail.comwrote:
Why can't I say the following;

Rectangle r = null;

The compiler tells me that null is a value type and can't be converted
to Rectangle. But I can't generally set any reference type to null.
For example, I can say:

MyClass c = null;
Thanks, makes sense now. And Yes, I did mean "I *can* generally ...".

Is there any specific reason why rectangle is a structure, not a
class. And how would I know this from the intellisense window, or is
it just something you learn.

Dom

Aug 13 '07 #4
On Aug 13, 5:27 pm, Dom <dolivas...@gmail.comwrote:
On Aug 13, 11:57 am, Dom <dolivas...@gmail.comwrote:
Why can't I say the following;
Rectangle r = null;
The compiler tells me that null is a value type and can't be converted
to Rectangle. But I can't generally set any reference type to null.
For example, I can say:
MyClass c = null;

Thanks, makes sense now. And Yes, I did mean "I *can* generally ...".

Is there any specific reason why rectangle is a structure, not a
class. And how would I know this from the intellisense window, or is
it just something you learn.

Dom
Traditionally structures are used instead of classes because they
require less resources. I am not sure if that is the reason here
though. In fact the line between structures and classes is very
blurred in .net.

You can tell if it is a structure and not a class in the intelli-sense
window because it has a slightly different icon.

Aug 13 '07 #5

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

Similar topics

15
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
2
by: AndrewW | last post by:
Hi I have an application that draws a selection rectangle over a map image. I can get it to work fine in IE and Opera, but not Firefox/Netscape. I've thrown the following small example...
2
by: (Pete Cresswell) | last post by:
Seems like I've been here before, but can't find anyting in Google. I've got two list boxes on a form. Seems to me like the inactive ListBox's selection rectangle should be something like...
6
by: kimos | last post by:
hi all, how to calculate the intersection of 2 rectangle a rectangle is the following: Rectangle makeRectangle (Point lowerLeft, Point upperRight) { Rectangle r;
5
by: woodBeeProgrammer | last post by:
this is a repost of a languishing query. is there a conventional value for "NAR" (Not A Rectangle) that Rectangle may be initialized to, sort of like NAN for doubles? Thanks in advance!!
3
by: | last post by:
I am having a hard time understanding the logic behind the Rectangle object. My problem has to do with the way the rectangle treats the "Width" property. For example, take the following rectangle...
5
by: DazedAndConfused | last post by:
I have a rectangle around text that I want to fill in with color. I do not know the height of the rectangle until I actually go through and draw out the text. Is there a way of filling in the...
4
by: RobinS | last post by:
I am drawing a rectangle on a picture that has already been drawn on the graphics area (a user control). It works something like this: //in the MouseDown event m_isDragging = true; m_oldX =...
1
by: kummu4help | last post by:
hi, i want to draw rectangle based on mousedrag event. if user dragging the mouse, then the rectangle on the applet should increase or decrease basing on current mouse coordinates. i have the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.