Advertisement
lightxx

Reference VS value type

Feb 26th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ObjectFun {
  4.     class Player {
  5.         public string PlayerName { get; set; }
  6.     }
  7.  
  8.     struct PlayerStruct {
  9.         public string PlayerName { get; set; }
  10.     }
  11.     class Program {
  12.         static void Main() {
  13.             var player = new Player {PlayerName = "Test1"};
  14.             var player2 = new Player {PlayerName = player.PlayerName};
  15.  
  16.             player.PlayerName = "New Name";
  17.             Console.WriteLine(player2.PlayerName);
  18.  
  19.             var player3 = new PlayerStruct { PlayerName = "Test1" };
  20.             var player4 = new PlayerStruct {PlayerName = player.PlayerName};
  21.  
  22.             player3.PlayerName = "New Name";
  23.             Console.WriteLine(player4.PlayerName);
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement