you can't extend static classes (unless they are marked as partial
), you need to create your own
or just extend int
itself
public static int ZeroIfLess(this int num)
{
if(num < 0)
{
return 0;
}
else
{
return num;
}
}
or just use a one-liner in-place instead:
Math.Max(num, 0)