I
I
issHarlequin2017-05-05 18:39:09
OOP
issHarlequin, 2017-05-05 18:39:09

How to create generic variables in C#?

Good afternoon, I am literally learning to write in C # for the third or fourth day and I am practically not familiar with programming. Please tell me how to organize the storage of variables.
In the current program, I use, say, 20 variables of the same class, each of which stores information about 15 features. Please tell me how to properly organize the storage of these variables, because now when I call any function that will interact with these variables in one way or another, I have to list them manually and, in addition, I can’t organize the program structure logically, because I'm afraid, in the course of jumping from function to function, to lose the real values ​​​​of variables due to the "garbage collector" (or whatever it is called) or the "visible field".
An example of how I store variables now (do not humiliate too much):

static void Main(string[] args)
        {
            ID homer = new ID("Гомер Симпсон", 120, "Спрингфилд", "Homer", "Donuts", 20, 4);
            ID simp = new ID("Мамин Симпатяга", 40, "Маминск", "Simpa98", "maman", 25, 3);   <b>
            ID brod = new ID("Папин Бродяга", 65, "Папинск", "CoolGuy", "pahan", 50, 2);
         }

PS Sorry for the stupid question, thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
Zelimkhan Beltoev, 2017-05-05
@issHarlequin

Use arrays or lists.

static void Main(string[] args)
{
   List<ID> persons = new List<ID>{
      new ID("Гомер Симпсон", 120, "Спрингфилд", "Homer", "Donuts", 20, 4),
      new ID("Мамин Симпатяга", 40, "Маминск", "Simpa98", "maman", 25, 3),
      new ID("Папин Бродяга", 65, "Папинск", "CoolGuy", "pahan", 50, 2),
   };
   ...
   // Дальше в методы передавайте всего одну переменную persons
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question