Lesson 1: Introduction to C#
1.1 What is C#?
C# (pronounced "C Sharp") is a modern, object-oriented programming language developed by Microsoft. It is widely used for building Windows applications, web applications, and games using Unity.
1.2 Why Learn C#?
- Versatile: Used in desktop, web, mobile, and game development.
- Strongly Typed: Helps catch errors at compile time.
- Object-Oriented: Encourages clean and modular code.
- Large Community: Extensive documentation and support.
Create Your First C# Program
Open a terminal and run:
dotnet new console -o MyFirstApp
cd MyFirstApp
dotnet run
This will create a simple "Hello, World!" program.
1.4 Understanding Variables and Data Types
Variables: A variable stores a value that can change.
string name = "Alice";
int age = 25;
Console.WriteLine(name + " is " + age + " years old.");
Data Types:
- int: Whole numbers (e.g.,
10
,-5
). - float: Decimal numbers (e.g.,
3.14f
). - double: Larger decimal numbers (e.g.,
3.14
). - string: Text (e.g.,
"Hello"
). - bool:
true
orfalse
.
1.5 Basic Operations
C# supports basic mathematical operations:
int x = 10;
int y = 5;
Console.WriteLine(x + y); // Addition
Console.WriteLine(x - y); // Subtraction
Console.WriteLine(x * y); // Multiplication
Console.WriteLine(x / y); // Division