C# for Beginners
C# for Beginners
Introduction
C# is a versatile, object-oriented programming language used for developing desktop, web, and mobile
applications.
This guide covers fundamental concepts for beginners.
1. Basics of C#
- C# syntax is similar to Java and C++.
- Example:
using System;
class Program {
static void Main() {
Console.WriteLine("Hello, World!");
2. Variables and Data Types
- Common data types: int, float, double, string, bool.
- Example:
int number = 10;
string name = "John";
3. Control Flow Statements
- Conditional Statements:
if (x > 10) { Console.WriteLine("Greater than 10"); } else { Console.WriteLine("Less than 10"); }
- Loops:
for (int i = 0; i < 5; i++) { Console.WriteLine(i); }
4. Object-Oriented Programming (OOP)
- Classes and Objects:
class Car {
public string model;
public Car(string model) { this.model = model; }
- Inheritance:
class ElectricCar : Car { public int batteryLife; }
5. Exception Handling
- Use try-catch blocks to handle errors.
- Example:
try { int result = 10 / 0; } catch (Exception e) { Console.WriteLine(e.Message); }
Conclusion
C# provides robust features for building applications. Understanding its basics helps in further learning.