Slasher Slasher - 2 days ago 5
C# Question

How to shorten boolean function

I have to shorten boolean function to one line. I'm a begginer in C# and I have no idea, how to shorten it.

static bool mod(int number)
{
if (number % 3 == 0)
{
return true;
}
else
{
return false;
}
}

Answer

You want this:

static bool mod(int number){    
   return number % 3 == 0;
}
Comments