Search⌘ K
AI Features

Relating C# Keywords to .NET Types

Explore how C# type keywords correspond to their .NET type aliases, including handling native-sized integers. Understand why using keywords can reduce the need for namespace imports and learn to locate .NET types within assemblies for effective application packaging and deployment.

One of the common questions is, “What is the difference between a string with a lowercase s and a String with an uppercase S?”

The short answer is easy: none. The long answer is that all C# type keywords, like string or int are aliases for a .NET type in a class library assembly.

Mapping the keyword to type

When we use the string keyword, the compiler recognizes it as a System.String type. When we use the int keyword, the compiler recognizes it as a System.Int32 type. Let’s see this in action with some code:

Step 1: In Program.cs, declare two variables to hold string values, one using lowercase string and one using uppercase String, as shown in the following code:

C#
string s1 = "Hello";
String s2 = "World";
WriteLine($"{s1} {s2}");
...