Values in C#
Our first program will demonstrate various value types in C#, including strings, integers, floats, and booleans. Here’s the full source code:
To run the program, save the code in a file named Values.cs
and use the C# compiler (csc
) to compile it, then execute the resulting executable.
C# has various value types including strings, integers, floats, booleans, and more. This example demonstrates some basic operations with these types:
- Strings can be concatenated using the
+
operator. - Integer and floating-point arithmetic work as expected.
- Boolean operations follow standard logical rules.
C# provides type inference for local variables, but in this example, we’ve used explicit Console.WriteLine statements for clarity. In practice, you might use var for local variable declarations where the type is obvious from the context.
This program gives you a glimpse of some basic value types and operations in C#. As you progress, you’ll encounter more complex types and operations that build on these fundamentals.