KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Definitely, I know the basic differences between unsigned integers ( uint ) and signed integers ( int ). I noticed that in .NET public classes, a property called Length is always using signed integers. Maybe this is because unsigned integers are not CLS compliant. However, for example, in my static function: public static double GetDistributionDispersion(int tokens, int[] positions) The parameter tokens and all elements in positions cannot be negative. If it's negative, the final result is useless. So if I use int both for tokens and positions , I have to check the values every time this function is called (and return non-sense values or throw exceptions if negative values found???), which is tedious. OK, then we should use uint for both parameters. This really makes sense to me. I found, however, as in a lot of public APIs, they are almost always using int . Does that mean inside their implementation, they always check the negativeness of each value (if it is supposed to be non-negative)? So, in a word, what should I do? I could provide two cases: This function will only be called by myself in my own solution; This function will be used as a library by others in other team. Should we use different schemes for these two cases? Peter P.S.: I did do a lot of research, and there is still no reason to convince me not to use uint :-)
Tags (comma-separated)
Save Edits
Cancel