can any one explain me what a difference between Decimal as Struct declaration and decimal as variable type in C#?
If they are the same things, so why both of them exists in C#.
The similar hapen with Bool and bool, String and string... etc...
can any one explain me what a difference between Decimal as Struct declaration and decimal as variable type in C#?
If they are the same things, so why both of them exists in C#.
The similar hapen with Bool and bool, String and string... etc...
The type is global::System.Decimal
; decimal
is just an alias to that. They both exist for the same reason that you use int
instead of System.Int32
- although in the case of decimal
the advantage is ... less clear - it basically comes down to "doesn't need a using System;
directive", but... meh.
They are identical/synonyms (assuming of course that your Decimal
resolves to System.Decimal
, and not some custom My.Decimal
).
decimal
is short hand notation for System.Decimal
structure.
so there is no difference between both of them.
If they are the same things, so why both of them exists in C#.
it's for user convenience.so user can type decimal
instead of System.Decimal
.
The similar hapen with Bool and bool, String and string
Yes similarly there are short hand notations
for many types.
few of them are as below:
-Type- -Short hand notation-
System.Byte - byte
System.Int16 - short
System.Int32 - int
System.Int64 - long
System.SByte - sbyte
System.UInt16 - ushort
System.UInt32 - uint
System.UInt64 - ulong
System.Single - float
System.Double - double
System.Boolean - bool
System.Char - char
String - string
Decimal is the CLR type and decimal is the c# keyword.
They are both the same thing to your programs and c# creates a Decimal in the background.Actually decimal is just alias of Decimal.
They are the same. The type decimal is an alias for System.Decimal.
So basically decimal is the same thing as Decimal. It's down to user's preference which one to use but most prefer to use int and string as they are easier to type and more familiar among C++ programmers.