V
V
vovkaooo12020-07-16 21:33:56
C++ / C#
vovkaooo1, 2020-07-16 21:33:56

How to create multiple numbers in c#?

I thought that you should not pile up the code with large ifs, because this is not correct.
The task is to constantly check several numbers that are static.
That is, with what help should I structure them into a single whole so that there are not many "a==.." I thought about implementing it with a loop, but it seems to me that this is not the right way at all
if (a==1 || a==2){}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dasha Tsiklauri, 2020-07-16
@vovkaooo1

string[] printer = {"jupiter", "neptune", "pangea", "mercury", "sonic"};
if(printer.Contains("jupiter")) {
// TODO
}

in your case, you write numbers to the array, and then
if (printer.Contains(a))

F
freeExec, 2020-07-16
@freeExec

Create a function for your simple check and use it where you need it. Containsof course it's fine if the check is not of type a > 7 && a % 2 == 0.

D
Dmitry Pavlov, 2020-07-17
@Stalker31

static void Prow(int a){
switch(a){
case 1:/*  выполнить необходимые действия  */break;
case 2:/*   выполнить необходимые действия */break;
case /* для остальных значений */:/* */break;}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question