Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I to shorten If else

My code looks like

private bool IsUserAditya(string username)
{
  return username == "Aditya"? true : false;
}

Can I shorten it further?

I would appreciate any help on this.

like image 717
Aditya Korti Avatar asked Dec 24 '22 16:12

Aditya Korti


1 Answers

Can I shorten it further?

Yes, a little bit

return username == "Aditya";

Any comparison in C# returns a bool, so no need to use the conditional operator.

like image 139
Tim Schmelter Avatar answered Jan 06 '23 19:01

Tim Schmelter