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

前端 未结 11 636
名媛妹妹
名媛妹妹 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:47

    There are a few cases where I really bother choosing.

    1. When I have memory limitations
    2. When I do bitshift operations
    3. When I care about x86/x64 portability

    Every other case is int all the way

    Edit : About x86/x64

    In x86 architecture, an int is 32 bits but in x64, an int is 64 bits

    If you write "int" everywhere and move from one architecture to another, it might leads to problems. For example you have an 32 bits api that export a long. You cast it to an integer and everything is fine. But when you move to x64, the hell breaks loose.

    The int is defined by your architecture so when you change architecture you need to be aware that it might lead to potential problems

提交回复
热议问题