Complete_Detailed_CSharp_Notes
Complete_Detailed_CSharp_Notes
1. Introduction to C#
part of its .NET initiative. It is designed for building a wide range of applications including web, mobile,
desktop, and games. C# is type-safe, scalable, and supports modern programming features like garbage
Example:
using System;
class Program {
Console.WriteLine("Welcome to C# Programming!");
Variables are containers for storing data values. Each variable in C# must be declared with a data type.
Example:
3. Operators
Complete C# Language Guide
Types of Operators:
- Arithmetic: +, -, *, /, %
Example:
int a = 10, b = 5;
int sum = a + b;
4. Conditional Statements
Conditional statements allow you to execute specific blocks of code based on certain conditions.
Types:
- if
- if-else
- else if
- switch
Example:
if (number > 0) {
Console.WriteLine("Positive number");
} else {
Console.WriteLine("Non-positive number");
5. Loops
Complete C# Language Guide
Types:
Example:
Console.WriteLine(i);
6. Arrays
An array is a collection of elements of the same type stored in a contiguous memory location.
Example:
Console.WriteLine(numbers[0]); // Outputs 1
7. Methods
Methods are blocks of code that perform a specific task. They make code reusable and organized.
Syntax:
returnType MethodName(parameters) {
// code
Example:
Complete C# Language Guide
Greet("John");
OOP is a programming paradigm that organizes code using objects and classes. Key principles:
Example:
class Animal {
Console.WriteLine("Animal speaks");
Console.WriteLine("Dog barks");
Example:
class Car {
Console.WriteLine("Driving...");
myCar.Drive();
Exception handling deals with errors that occur during program execution. C# uses try-catch-finally blocks.
Example:
try {
int result = 10 / 0;
} catch (DivideByZeroException e) {
Example:
File.WriteAllText("file.txt", "Hello");
Console.WriteLine(content);
Interface Example:
interface IShape {
void Draw();
Delegate Example: