hi. as you may know we have bool and Boolean in c# that work completely the same. or single and float accept same values with same range and....... is there any reason for it?
why we have data type alias in c#?
Types like System.Float and System.Boolean come from the CTS (Common Type System), part of the CLI (Common Language Infrastructure) standard. This standard is defined in ECMA-335. They have nothing, per se, to do with C#.
C# is a language generally built on top of the CLI specification; it's standard (defined in ECMA-334) requires that a certain minimal subset of CLI be exposed through. That includes exposing the CTS types. The language then provides the common C-like aliases "bool" and "float" and such for aesthetics or convenience.
2 hours ago, jpetrie said:requires that a certain minimal subset of CLI be exposed through. That includes exposing the CTS types
thanks a lot for your answer but can you tell me why its required?
By requiring it, the standard is ensuring that C# can be compiled to an intermediate representation any conforming CLI implementation can run, and also that it can inter-operate easily with other such languages (VB.NET, for example). This ability to inter-operate was a key design goal of the platform at the time; supporting it eases adoption and thus increases how quickly the ecosystem will spread.
I encourage you to read some of those linked standards (the introduction material in particular). They're considerably easier to digest than, say, the C++ standard.
The ones with capital letters are blittable types. I can't go more into depth, but maybe, just maybe it's related that in C# the booleans, shorts, and bytes are represented with 4 bytes if on the stack, or maybe it was just the bools... and I don't know if it applies to structs on the stack.
https://docs.microsoft.com/en-us/dotnet/framework/interop/blittable-and-non-blittable-types
On 3/17/2018 at 3:25 PM, RnzCpp said:The ones with capital letters are blittable types.
This is not accurate. There is no difference between `System.Boolean` and `bool`. The latter is simply the C# language alias for the former, and there is no functional difference in their usage. I don't think there's anything dictating how much space primitive types take on the stack -- that is an implementation detail and likely depends on the runtime and optimization level being used.
Traditionally, `System.Boolean` is not considered a blittable type because the Win32 boolean type is 32-bits, whereas the .NET representation is 8-bytes. This behavior probably made sense when .NET was first designed, primarily for Win32 systems.