I suggest you ...

'number' type

BigInteger and decimal are annoying. So verbose and with BigInteger we must create a class, the parameter is an string, etc.

"number" will be a dynamic type which accept infinite integers and decimals, and he only can be a number.

How to use:
number variable=Int32.MaxValue+999; // > Int32
variable=2.333333333333; // BigInteger to decimal without casting

If C# adds this Python feature, he will be the best language ever.

58 votes
Vote
Sign in
(thinking…)
Password icon
Signed in as (Sign out)
You have left! (?) (thinking…)
Andreu shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

2 comments

Sign in
(thinking…)
Password icon
Signed in as (Sign out)
Submitting...
  • Martheen commented  ·   ·  Flag as inappropriate

    Wouldn't it hurt performance? Introduce number and suddenly the compiler can't optimize the code since it can't assume the variable size and operation. The JIT may handle things better by knowing the value and observing repeated operations, just like how V8 handle number operations.

    This might be custom implemented using Roslyn, essentially creating a syntactic sugar for BigInterer, BigRational
    http://bcl.codeplex.com/wikipage?title=BigRational&referringTitle=Home or other similar class. Even then, there's hardly any real world need for BigRational (financial calculation is accurate enough with decimal).

    So this addition will definitely hurt performance, and may be custom implemented for those who need it. I say keep it out of core C#.

  • Philippe commented  ·   ·  Flag as inappropriate

    Given that Int32.Max + 999 is the addition of two int, the above code won't give the expected result as the conversion from int to number would occurs after the addition (and thus after the overflow). The same that presently happen if one would do : double variable = Int32.Max + 999.

    Modifying the rules might have compatibility implication...as unmodified code might change behavior in some cases.

    Thus one would have to write something like Int32.MaxValue + 999n (with a suffix to indicate number type).

Feedback and Knowledge Base