C# Method Resolution, long vs int

后端 未结 3 1851
陌清茗
陌清茗 2020-12-03 20:43
class foo
{
  public void bar(int i) { ... };
  public void bar(long i) { ... };
}


foo.bar(10);

I would expect this code to give me some error, o

3条回答
  •  春和景丽
    2020-12-03 21:04

    I would say if you exceed below limit

    -2,147,483,648 to 2,147,483,647
    

    control will go to long

    Range for long

    –9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
    

    Max value for int

    foo.bar(-2147483648);
    

    or

    foo.bar(2147483648);
    

    Long will get control if we exceed the value by 2147483648

提交回复
热议问题