The Primitive Types Available in C# The list of primitive types available in C# is very similar to C and C++. One of the major reasons for the cross-language interoperability of the .NET Framework is that all languages share a common type system: the CTS. The primitive types in C# are just aliases for CTS types. Table 4-4 shows the primitive types available in C#. Table 4-4. A Mapping of C# types to CTS types
Most of the familiar primitive types from C and C++ like int, long, short, char, float, and double are present in C#. C# also supports unsigned types like uint, ushort, and unlong, but keep in mind that these unsigned types are not CLS compliant. Therefore, if you do expose types from your libraries that use these unsigned types in their interface, those libraries will not be usable from many managed code languages including VB.NET. Avoid unsigned types in your interfaces if you want to write components that may be consumed by languages other than C#. Note The CLS specifies the features that all managed code languages must support as a minimum. With C#, as in most managed-code languages, you can use either the language-specific alias or the CTS type name freely and interchangeably. In other words, declaring a variable to be of type "int" is exactly the same as declaring it to be of type "System.Int32". In addition, a function that accepts a parameter of type float will also accept a parameter that is typed as System.Single. |
Team-Fly |
Top |