Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use int or UInt16?

Tags:

c#

This may be somewhat trivial, but in C# do you prefer int or UInt16 when storing a network port in a variable? Framework classes use int when dealing with a network port although UInt16 actually represents the valid values.

like image 358
JC. Avatar asked Mar 01 '10 22:03

JC.


1 Answers

signed (int / short etc, rather that uint / ushort) have the advantage of being CLS compliant, so that is recommended unless you have a good reason.

Re int vs short - in most cases it is more efficient to compute with int (or uint), since all the operators are optimised for this. If you are only storing and retrieving it then this isn't an issue, of course.

like image 180
Marc Gravell Avatar answered Oct 11 '22 03:10

Marc Gravell