X hits on this document

1054 views

0 shares

0 downloads

0 comments

172 / 396

Chapter ‎18   Unsafe code

When a property or indexer declared in a struct-type is the target of an assignment, the instance expression associated with the property or indexer access must be classified as a variable. If the instance expression is classified as a value, a compile-time error occurs. Because of §‎7.5.4, the same rule also applies to fields.

Given the declarations:

struct Point { int x, y;

public Point(int x, int y) { this.x = x; this.y = y; }

public int X { get { return x; } set { x = value; } }

public int Y { get { return y; } set { y = value; } } }

struct Rectangle { Point a, b;

public Rectangle(Point a, Point b) { this.a = a; this.b = b; }

public Point A { get { return a; } set { a = value; } }

public Point B { get { return b; } set { b = value; } } }

in the example

Point p = new Point(); p.X = 100; p.Y = 100; Rectangle r = new Rectangle(); r.A = new Point(10, 10); r.B = p;

the assignments to p.X, p.Y, r.A, and r.B are permitted because p and r are variables. However, in the example

Copyright Microsoft Corporation 1999-2003. All Rights Reserved.159

Document info
Document views1054
Page views1054
Page last viewedSat Dec 10 15:33:58 UTC 2016
Pages396
Paragraphs9401
Words133190

Comments