Difference between Decimal and decimal

前端 未结 5 1770
野性不改
野性不改 2021-01-01 10:39

If someone could explain to me the difference between Decimal and decimal in C# that would be great.

In a more general fashion, what is the difference between the lo

5条回答
  •  不知归路
    2021-01-01 11:04

    As C# is a .NET language, all types must map to a .NET Framework Type.

    To answer your first question, decimal is an Alias of the System.Decimal .NET Framework type. They may be used interchangeably.

    To answer your second question, both Decimal and decimal should extend the same functions, including both from the created variable and from the "Structure" of the value type itself.

    decimal FirstDec = 12;
    Decimal SecondDec = 13;
    decimal ThirdDec = decimal.Ceiling(FirstDec, SecondDec);
    Decimal FourthDec = Decimal.Floor(ThirdDec);
    bool isEqual = FirstDec.Equals(SecondDec) && FourthDec.Equals(ThirdDec);
    

    The following MSDN Page for Built-In Types will show you which System.ValueType each alias maps to. And for Decimal and decimal specifically, you can reference this MSDN Page for Decimal.

提交回复
热议问题