D
D
Demigodd2017-03-07 10:13:34
C++ / C#
Demigodd, 2017-03-07 10:13:34

How to choose the maximum value from 3 int values ​​in c#?

Let's say there are 3 variables 1zn, 2zn, 3zn and they have an int value. How can I make the code process these values ​​and select the maximum one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
leremin, 2017-03-07
@Demigodd

int max = Math.Max(1zn, Math.Max(2zn, 3zn));

L
LiptonOlolo, 2017-03-14
@LiptonOlolo

Or so for an array:

using System.Linq;
int[] nums = { 0, 1, 2, 3, 4, 5, 6, 3 };
int max = nums.Max(); //Result: 6

Also, if you have variables, then:
using System.Linq;
int[] nums = { zn1, zn2, zn3 }; //в именах переменных, первый символ не может быть знаком (точка, запятая и т.п.) или цифрой
int max = nums.Max();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question