Does it really matter to distinct between short, int, long?

前端 未结 11 635
名媛妹妹
名媛妹妹 2021-01-17 09:46

In my C# app, I would like to know whether it is really important to use short for smaller numbers, int for bigger etc. Does the memory consumption really matter?

11条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-17 10:36

    The simple answer is that it's not really important.

    The more complex answer is that it depends.

    Obviously you need to choose a type that will hold your datastructure without overflowing, and even if you're only storing smaller numbers then choosing int is probably the most sensible thing to do.

    However, if your application loads a lot of data or runs on a device with limited memory then you might need to choose short for some values.

提交回复
热议问题