Should I use int or UInt16?
This may be somewhat trivial, but in C# do you prefer int or UInt16 when storing a network port in a variable? Frame开发者_Go百科work classes use int when dealing with a network port although UInt16 actually represents the valid values.
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.
if you have 32 bit processor and you will use 16bit value (for memory economy) it will be aligned to 32bit. So I think it is not so important use 16bit uint instead of 32bit value.
精彩评论