Point is a struct
but I can do both
Point a;
Write(a.X);
Write(a.Y);
and
Point a = new Point(1,1);
Write(a.X);
Write(a.Y);
.....seems confusing! 3 3801
Action <am***@hotmail. com> wrote: Point is a struct but I can do both
Point a; Write(a.X); Write(a.Y);
Yes, although it's a bad idea to do that - I'd always write the above
as
Point a = new Point();
Write (a.X);
Write (a.Y);
It'll do the same thing (always, I believe) but it means that the whole
of the struct is definitely assigned.
and Point a = new Point(1,1); Write(a.X); Write(a.Y); ....seems confusing!
Why? Basically "new" returns a new *value* for value-types, not a new
reference.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Does this mean that
Point a = new Point(1,2);
Write (a.X);
Write (a.Y);
1. a new Point is created
2. Value of the newly created Point is assigned to Point "a"
3. the "new Point" is destroyed, as Point "a" is a struct, it didn't really
points to the "new Point", so the "new Point" has zero reference => GC clean
it up....
is this the case?
thx!
"Jon Skeet" <sk***@pobox.co m> wrote in message
news:MP******** *************** @news.microsoft .com... Action <am***@hotmail. com> wrote: Point is a struct but I can do both
Point a; Write(a.X); Write(a.Y);
Yes, although it's a bad idea to do that - I'd always write the above as
Point a = new Point(); Write (a.X); Write (a.Y);
It'll do the same thing (always, I believe) but it means that the whole of the struct is definitely assigned.
and Point a = new Point(1,1); Write(a.X); Write(a.Y); ....seems confusing!
Why? Basically "new" returns a new *value* for value-types, not a new reference.
-- Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Action <am***@hotmail. com> wrote: Does this mean that Point a = new Point(1,2); Write (a.X); Write (a.Y); 1. a new Point is created 2. Value of the newly created Point is assigned to Point "a" 3. the "new Point" is destroyed, as Point "a" is a struct, it didn't really points to the "new Point", so the "new Point" has zero reference => GC clean it up....
is this the case?
Not quite - because Point is a value type, there *is* nothing on the
heap to be cleaned up. It's just the same as doing:
int a=5;
int b=10;
int x = a+b;
- the addition is performed, and the value is assigned to x. Exactly
the same kind of thing is happening here - the point is created, and
then assigned to the variable. At no point does anything need to be on
the heap - there are no references involved.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bilo |
last post by:
Need Help with
System.Drawing.Point b = new System.Drawing.Point(int x , int y)
I want to move a window when mous is down and mous is moving
private void label1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left && video.Fullscreen != true)
{
|
by: Richard |
last post by:
I each time get errors when I use an .bmp or ,.gif file as source but
whenever I use a .jpg file it works perfect.
Why is that? and how to fix it?
I almost have no knowledge about the system.drawing and so I am in the dark
about this.
This is my code
|
by: hzgt9b |
last post by:
I'm building a dataset that writes out a Point type value.
Here's the code that I've got:
1 Dim dsContent As DataSet = New DataSet("content")
2 Dim dtAsset As DataTable = New DataTable("asset")
3 Dim dcPk(0) As DataColumn
4 dcPk(0) = _
5 dtAsset.Columns.Add("fullName", Type.GetType("System.String"))
6 ...
|
by: Jerry J |
last post by:
I want to use the System.Drawing.Image class. According to the help file,
this is an abstract base class. Because it is supposedly abstract, I created
another class that inherits from it. However, when I did this I got the
following error:
'System.Drawing.Image.Image()' is inaccessible due to its protection level
Looking at other online...
|
by: Marc the Demi-Programmer |
last post by:
I am overriding WncProc to make sure my form's location stays within
specified parameters. Basically, it has to stay at the top of the
screen and not be off to either of the sides. All that works when the
form is in its minimal size. However, when the form is maximized using
the appropriate button the code that is supposed to set the...
| |
by: dr |
last post by:
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to
recenter the form on the screen at some point other then startup.
|
by: =?Utf-8?B?R2lkaQ==?= |
last post by:
Hi,
what is the unit of System.Drawing.Size?
when i'm writing Size = (1024,784), is it pixel? or something else?
Thanks,
|
by: Dave Bootsma |
last post by:
I have an application where I want to redraw a polygon from points I
retrieve from a file.
The file is read with streamreader line by line each line contains the
points for each polygon.
Below is a typical line from my file.
500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748
Each set of x,y coordinates is separated by a space....
|
by: ouzsharp |
last post by:
The follwing class works well when used in a C# console application:
namespace ScreenShotDemo
{
/// <summary>
/// Provides functions to capture the entire screen, or a particular window, and save it to a file.
/// </summary>
public class ScreenCapture
{
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |