I see many times using native and literals “keywords” in C# articles. What do they mean?
examples:
The Empty constant holds the empty string value. We need to call the
String constructor so that the compiler doesn’t mark this as a
literal. Marking this as a literal would mean that it doesn’t show up
as a field which we can access from native.
Simple/primitive types
Both languages support a number of built-in
types which are copied and passed by value rather than by reference.
Java calls these types primitive types, while they are called simple
types in C#. The simple/primitive types typically have native support
from the underlying processor architecture.
From the C# spec section 2.4.4:
So for example there are literals for strings and numbers:
… but C# has no literal syntax for dates and times; you’d have to use:
As for native support – there are different levels of “native” here, but as far as C# is concerned, I’d usually consider it type-specific support in whatever output format is used. So for example, there are IL instructions to deal with the binary floating point types (
float,double) but when the C# compiler emits code dealing withdecimalvalues, it has to call the operators declared inSystem.Decimal. I’d therefore consider thatfloatanddoublehave native support in IL, butdecimaldoesn’t.(It would be possible to write a C# compiler targeting a different platform which did have native support for
decimal– or which didn’t have native support forfloatanddouble, for example. Unlikely, but possible.)Then when the IL is being run in an execution engine, that will be running on top of “real” native code – x86 for example – which can have specific support for certain types. That’s another level of “native”. For example, if someone came up with a new version of IL which included native support for
decimal, that wouldn’t mean that the CPUs themselves suddenly gained native support.