Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    Demonstrations of structs in C#.Lecture 2 - slide 12 : 43
Program 1
using System;

public struct Point {   
  public double x, y;   
  public Point(double x, double y){this.x = x; this.y = y;}   
  public void Mirror(){x = -x; y = -y;}                       
} // end Point

public class StructDemo{

 public static void Main(){
   Point p1 = new Point(3.0, 4.0),      
         p2;                            

   p2 = p1;                             
   
   p2.Mirror();                         
   Console.WriteLine("Point is: ({0},{1})", p2.x, p2.y);  
 }
}
 
 
Definition of struct Point
Two double fields
A constructor
A Mirror method
 
 
 
 
 
The point p1 is initialized via the constructor.
The point p2 is uninitialized.
 
The point in p1 is copied - field by field to p2.
 
The operation, Mirror, is called on p2.
(-3,-4)