In c# are Decimal and decimal different?
In c# if I use decimal
(lower case 'd'), the IDE shows it in dark blue (like int
). If I use Decimal
(upper case 开发者_开发知识库'd'), the IDE shows it in teal (like a class name). In both cases the tooltip is struct System.Decimal
.
Is there any difference? Is one "preferred"?
Nope; identical. decimal
is defined as an alias to System.Decimal
, and is generally preferred, except in public method names, where you should use the proper name (ReadDecimal
, etc) - because your callers might not be C#. This is more noticeable in int
vs ReadInt32
, etc.
There certainly isn't the Java-style boxing difference.
(of course, if you do something like declare a more-namespace-local Decimal
that does something completely different, then there are differences, but that would be silly).
It is the same thing, Decimal is the .Net type and decimal is the c# keyword.
System.Decimal
it's a .NET Framework type, decimal
is an alias in the C# language.
Both of them are compiled to System.Decimal
in IL, so there is no difference.
Is exactly the same thing about int
and System.Int32
, string
and System.String
etc..
decimal is an alias to Decimal. They are the same thing.
The dark blue is for language keywords, teal is for types. In the case of decimal
it's a keyword representing a type alias.
decimal
is a keyword and always refers to the struct System.Decimal
defined in base class library. Decimal
usually means the same thing as most people have using System;
on top of their source code. However, strictly speaking, those are not identical (you can't blindly find-and-replace them):
namespace Test {
class Decimal { }
}
// File2.cs
using Test;
class DecimalIsNotdecimal {
void Method(decimal d) { ... }
void Method(Decimal d) { ... } // works!
}
No. They are just shortcuts.
If you hover over decimal you'll see System.Decimal. As with int and System.Int32, object and System.Object, string and System.String, double and System.Double
I prefer the decimal and string, but I really think its personal
No, they're the same thing. One is colored as a keyword (decimal), the other is colored as a type (Decimal). The keyword is just an alias for the type.
Its the same thing. 'deciaml' is the c# keyword for System.Decimal.
This applied to other types like string and String etc.
精彩评论