I have the following method:
virtual public int nonNeg(int? numIn)
{
if ((numIn < 0) || (numIn ==null))
{
return 0;
}
else return (int)numIn;
}
I want to be able to have a single method which could take in either bytes, shorts, or ints to force these values to a nonnegative number. How could I accomplish this?
I would not normally suggest this, but off the top of my head the following overloads should cover most your cases. They will cover the nullable types and the non-nullable types, the compiler will select the appropriate overload.