-
Notifications
You must be signed in to change notification settings - Fork 2
CSharp Basics Types Variables
Joe Care edited this page Dec 22, 2025
·
1 revision
This lesson introduces the most common built-in types in C# and how to declare and assign variables.
Related wiki pages:
- General overview:
CSharpBible.md - Input/output basics:
CSharp-Basics-ConsoleWriteLine-DateTime.md,Lesson20.12.2025.md(to be renamed)
Official docs:
- Types and variables: https://learn.microsoft.com/dotnet/csharp/fundamentals/types/
Some frequently used types:
-
int– 32-bit signed integer (e.g.10,-5,0) -
double– double-precision floating-point (e.g.3.14,-2.7) -
string– text enclosed in double quotes (e.g."Hello") -
bool–trueorfalse -
char– single character in single quotes (e.g.'A')
Explicit typing:
int count = 10;
string greeting = "Welcome to C#!";
bool isActive = true;Type inference with var:
var message = "Hello"; // inferred as string
var number = 42; // inferred as intvar is still statically typed; the compiler infers the type from the right-hand side.
using System;
namespace BasicConcepts
{
public class Program
{
public static void Main(string[] args)
{
var greeting = "Welcome to C#!";
Console.WriteLine(greeting);
}
}
}This prints:
Welcome to C#!
For more console examples see CSharp-Basics-ConsoleWriteLine-DateTime.md and CSharpBible-Library-ConsoleLib.md.
- Try declaring variables of each primitive type and printing them.
- Combine this with input from
Console.ReadLineas shown inLesson20.12.2025.md(to be renamed to an I/O focused title).