How to compare multiple variables in c#? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to compare multiple variables in c#?

3rd Aug 2018, 7:44 AM
Muhammad Talha
Muhammad Talha - avatar
3 Answers
+ 2
the simplest way is to compare it using AND && for example you can do this: if (a == b && a == c && b == c) { //insert code here } However if you have many variables, you could build an array and use the IEnumerable. This code verifies if all values are equal to a variable foo if(new[] { a, b, c, d, e, f, g, h, i, j }.All(x => x == foo));
3rd Aug 2018, 9:14 AM
Davide Ferrero
Davide Ferrero - avatar
+ 1
thankx bro
3rd Aug 2018, 9:32 AM
Muhammad Talha
Muhammad Talha - avatar
0
Mete todas las variables en un array y has las comparaciones con un for
3rd Aug 2018, 9:04 PM
Roberto Hodge
Roberto Hodge - avatar