I'm learning C# and I asked the best method to interact with variable of a class out of this class. I thought about this:
public class Character { private int x, y; public Character(int posX, int posY) { x = posX; y = posY; } public int X { get { return x; } set { x = value; } } public int Y { get { return y; } set { y = value; } } }` class MainClass { public static void Main (string[] args) { Character hero = new Character (42, 36); Console.WriteLine (hero.X); Console.WriteLine (hero.Y); hero.X = 5; Console.WriteLine (hero.X); } } I don't know if this method is good or optimized but it works. But, if I want do this for 10 variables, my class will do minimum (more if I want add a test in get/set) 100 lines just for my variables... Do you know an other method to proceed? Or how I can compress this method? Thank you!