Guest User

ref return

a guest
Jan 15th, 2014
198
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Vector2 {
  2.   float x;
  3.   float y;
  4.  
  5.   public Vector2(float x, float y) { this.x = x; this.y = y; }
  6. }
  7.  
  8. class Example {
  9.   static void Main() {
  10.     Vector2[] arr = new Vector2[] { new Vector2(0,0), new Vector2(1,1) }
  11.     List<Vector2> list = new List<Vector2>();
  12.     list.Add(new Vector2(0,0));
  13.     list.Add(new Vector2(1,1));
  14.  
  15.     arr[0].x = 1;  // works?
  16.     list[0].x = 1; // would work if list[] could return reference to element
  17.   }
  18. }
RAW Paste Data