Complete C# Language Guide
1. Introduction to C#
C# (pronounced C-Sharp) is a modern, object-oriented programming language developed by Microsoft. It is
used to build Windows applications, web applications, and games using the .NET framework.
2. Variables and Data Types
Variables store data. Example: int age = 25;
Data types include:
- int (integer)
- float (decimal numbers)
- char (single character)
- string (text)
- bool (true/false)
3. Operators
C# supports operators such as:
- Arithmetic (+, -, *, /)
- Comparison (==, !=, >, <)
- Logical (&&, ||, !)
4. Conditional Statements
Used to make decisions:
Example:
if (age > 18) {
Console.WriteLine("Adult");
} else {
Console.WriteLine("Minor");
5. Loops
Complete C# Language Guide
Used to repeat actions:
- for loop
- while loop
- do-while loop
6. Arrays
Arrays store multiple values:
int[] numbers = {1, 2, 3, 4};
Access elements by index: numbers[0]
7. Methods
Methods are blocks of code that perform tasks:
Example:
void Greet() {
Console.WriteLine("Hello");
8. Object-Oriented Programming (OOP)
OOP has 4 key concepts:
- Encapsulation: Hiding data using classes
- Inheritance: One class inherits another
- Polymorphism: Same method, different behavior
- Abstraction: Hiding complex implementation
9. Classes and Objects
Class is a blueprint, object is an instance.
Example:
class Car {
public string color;
}
Complete C# Language Guide
Car myCar = new Car();
10. Exception Handling
Used to handle errors:
try {
// code
} catch (Exception e) {
Console.WriteLine(e.Message);
11. File Handling
Use System.IO to read/write files:
File.WriteAllText("file.txt", "Hello");
string text = File.ReadAllText("file.txt");
12. Advanced Topics
- Interfaces
- Delegates
- Events
- LINQ
- Async/Await (for asynchronous programming)