Search code examples
c#sqlcoding-styletypesunsigned

Should I use uint if my function is logically intended to return only natural numbers?


Let's consider a function which gets a person's birth date and returns his age (in whole years). In case of the date is in future it throws an exception. What type should it return - uint or int? uint seems logical as a natural constraint. Or is it better to use more usual int?


Solution

  • the unsigned numbers are not CLS-compliant, so in general: No, don't use them.
    Certainly not in public interfaces.