Csharp Struct and Class
Feature
struct
class
public struct Point
{
public int x;
public int y;
}
Point a = new Point { x = 1, y = 2 };
Point b = a;
b.x = 99;
Debug.Log(a.x); // 🔹 Outputs 1 (copy was independent)public struct Point
{
public int x;
public int y;
}
Point a = new Point { x = 1, y = 2 };
Point b = a;
b.x = 99;
Debug.Log(a.x); // 🔹 Outputs 1 (copy was independent)public class Player
{
public string Name;
}
Player p1 = new Player { Name = "Alice" };
Player p2 = p1;
p2.Name = "Bob";
Debug.Log(p1.Name); // 🔸 Outputs "Bob" (reference changed both)