Can C# have statement in condition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can C# have statement in condition

How can i use sth like this: if (int x = SomeMethodReturnsInt() != 1) { //play with x } instead of int x = SomeMethodReturnsInt(); if (x != 1) { } Is it possible?

20th May 2018, 2:39 PM
Soheil Khodaei
1 Answer
+ 1
It is possible to have a statement in a condition. It is not allowed to declare a new variabele in a if statement. https://code.sololearn.com/cHEYbt5PHwWO/?ref=app
20th May 2018, 2:55 PM
sneeze
sneeze - avatar