Should I use int or Int32

前端 未结 30 2595
野性不改
野性不改 2020-11-22 11:52

In C#, int and Int32 are the same thing, but I\'ve read a number of times that int is preferred over Int32 with no reason

30条回答
  •  梦谈多话
    2020-11-22 12:27

    They both declare 32 bit integers, and as other posters stated, which one you use is mostly a matter of syntactic style. However they don't always behave the same way. For instance, the C# compiler won't allow this:

    public enum MyEnum : Int32
    {
        member1 = 0
    }
    

    but it will allow this:

    public enum MyEnum : int
    {
        member1 = 0
    }
    

    Go figure.

提交回复
热议问题