[Solved] C# what does (bool ? string : string) do? [duplicate]


it’s equivalent to

if (b)
{
     return s1;
}
else
{
     return s2;
}

Edit: As Alexey pointed out, I should clarify. return here isn’t the return from your specific function it’s just saying that the statement (b ? s1 : s2) will evaluate to either s1 or s2 based on the value of b.

Learn more here: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/conditional-operator

1

solved C# what does (bool ? string : string) do? [duplicate]