V3nom's
  • Welcome
  • Getting Started
    • CEH v13
    • Basics of Networking
      • Network Models
        • Application Layer in OSI ->
        • Presentation Layer in OSI ->
          • Comprehensive list of character encoding formats
        • Session Layer in OSI ->
        • Transport Layer in OSI ->
        • Network Layer in OSI ->
        • Data Link Layer in OSI ->
        • Physical Layer ->
    • Arch Linux Installation Guide
    • How to add VBoxLinuxAdditions.run in Debian Based Linux Distros
    • C# Programming Language
  • Research Papers
    • Word Embedding for Anomaly Detection
    • Build your own Redis
    • Blockchain Technology
    • Interactive blocks
    • OpenAPI
    • Integrations
  • Risk Analysis & Mitigation Notes
    • Risk Analysis & Mitigation
      • Unit 1: An Introduction to Risk Management
      • Unit 2: The Threat Assessment Process
      • Unit 3: Vulnerability Issues
      • Unit 4 ( Risk Analysis & Mitigation )
      • Unit 5 ( Risk Analysis & Mitigation )
  • Ethical Hacking
    • Ethical Hacking Syllabus
      • Unit I: Introduction ( English )
      • Unit I: Introduction ( Hinglish )
      • Unit II: The Business Perspective ( English )
      • Unit II: The Business Perspective ( Hinglish )
      • Unit III: Preparing for a Hack ( English )
      • Unit III: Preparing for a Hack ( Hinglish )
      • Unit IV: Enumeration ( English )
      • Unit IV: Enumeration ( Hinglish )
      • Unit V: Deliverables ( English )
      • Unit V: Deliverables ( Hinglish )
  • .NET Framework Notes
    • .NET Framework Syllabus
      • Unit - I ( Hinglish Version )
      • Unit - I ( English - Version for exams )
      • Unit - II ( Hinglish Version - For Understanding )
      • Unit - II (English Version - for papers)
      • Unit - III ( Hinghlish Version )
      • Unit - III ( English - Version )
      • Unit - IV ( Hinglish Version )
      • Unit - IV ( English Version )
      • Unit - V ( Hinglish Version )
      • Unit - V ( English Version )
  • IOT
    • unit 1
    • unit 2
    • unit 3
    • unit 4
    • unit 5
  • AD-Hoc and Wireless Networks
    • Unit 1 ( Hinglish )
    • unit 2 Hinglish
    • All assignments answers with questions
    • Mind Maps for All Questions
    • Page
  • Distributed Systems
    • Unit 1
    • Unit 2
    • Unit 3
    • Unit 4
    • Unit 5
  • Group 1
    • 1’s and 2’s Complement
    • Direct Memory Access
    • Register Transfer Level
    • Interrupt-Based Input/Output (I/O)
    • Memory and CPU Design
    • Instruction Cycle
    • Addressing Modes
    • Pipelining
    • Three Types of Hazards
    • All Types of Differences Tables
    • Parallel Processing
    • Addition/Subtraction Conversion
    • Data Representation
    • Page 1
Powered by GitBook
On this page
  • 1. C# Object-Oriented Programming (OOPs)
  • 1.1. Encapsulation
  • 1.2. Inheritance
  • 1.3. Polymorphism
  • 1.4. Object Lifetime
  • 1.5. Components and Modules
  • 1.6. Windows Forms
  • 1.7. Interface
  • 1.8. Cloneable Objects
  • 1.9. Comparable Objects
  • 1.10. Collections and Namespaces
  • 2. Advanced Class Construction
  • 2.1. Custom Indexer
  • 2.2. Overloading Operators
  • 2.3. Delegates
  • 2.4. Events
  1. .NET Framework Notes
  2. .NET Framework Syllabus

Unit - II ( Hinglish Version - For Understanding )

1. C# Object-Oriented Programming (OOPs)

C# ek Object-Oriented Programming (OOP) language hai, jo code ko objects ke around organize karta hai, actions ke bajaye. Yahan pe details diye gaye hain:

1.1. Encapsulation

Encapsulation ka matlab hota hai kisi object ki internal state ko chhupana aur sirf wohi cheez expose karna jo dusre parts ko interact karne ke liye zaroori ho. Yeh access modifiers aur properties ke through achieve hota hai. Encapsulation kyu important hai?

  • Data Protection: Yeh ensure karta hai ki object ka internal state unintended ya unauthorized modification se bach sake.

  • Code Maintenance: Tum internal logic ya implementation ko bina external interface ko affect kiye modify kar sakte ho, jisse system flexible aur maintainable banta hai.

Example:

public class BankAccount
{
    private double balance; // private field, not directly accessible

    // Public method to access and modify the private field
    public void Deposit(double amount)
    {
        if (amount > 0)
            balance += amount;
    }

    public double GetBalance() // Public method to get the balance
    {
        return balance;
    }
}

Yahan pe balance BankAccount class ke andar encapsulated hai, aur usko Deposit aur GetBalance jaise public methods ke through control kiya jata hai.

1.2. Inheritance

Inheritance tumhe code reuse karne ka option deta hai, jisme ek class doosri class se members (fields aur methods) inherit karti hai. Isse tum existing class ka behavior extend ya modify kar sakte ho, bina redundancy ke. Inheritance types in C#:

  • Single Inheritance: Ek class sirf ek base class se inherit kar sakti hai.

  • Multilevel Inheritance: Ek class doosri derived class se inherit karti hai, jo apne aap kisi aur class se inherit karti hai (hierarchy banati hai).

Example:

class Vehicle
{
    public void StartEngine()
    {
        Console.WriteLine("Engine started.");
    }
}

class Car : Vehicle // Inherits from Vehicle
{
    public void Honk()
    {
        Console.WriteLine("Horn honked.");
    }
}

Car class Vehicle se inherit kar rahi hai, isliye usse StartEngine() method bhi mil jata hai. Yeh inheritance ka faida dikhata hai.

Key Concepts:

  • Overriding Methods: Derived classes base class ke methods ko override kar sakti hain taaki custom functionality provide ki ja sake. Yeh virtual keyword ke saath base class mein aur override keyword ke saath derived class mein hota hai.

Example:

class Animal
{
    public virtual void Speak()
    {
        Console.WriteLine("Animal speaks");
    }
}

class Dog : Animal
{
    public override void Speak()
    {
        Console.WriteLine("Dog barks");
    }
}

1.3. Polymorphism

Polymorphism ka matlab hai ki alag-alag types ke objects ko ek common base type ke object ke roop mein treat kiya ja sakta hai. Isse ek hi method ya property alag-alag objects ke liye alag tarike se behave kar sakti hai. Types of Polymorphism:

  • Compile-time Polymorphism: Yeh method overloading aur operator overloading ke through achieve hota hai.

  • Run-time Polymorphism: Yeh method overriding ke through achieve hota hai, jisme base class ke reference ko derived class ke objects ke liye use kiya jata hai.

Example of Compile-time Polymorphism (Method Overloading):

class Calculator
{
    public int Add(int a, int b) { return a + b; }
    public double Add(double a, double b) { return a + b; }
}

Yahan Add method ko integers aur doubles dono ke liye overload kiya gaya hai, jo same functionality provide karta hai but alag input types ke saath.

Example of Run-time Polymorphism (Method Overriding):

class Animal
{
    public virtual void Speak()
    {
        Console.WriteLine("Animal speaks");
    }
}

class Dog : Animal
{
    public override void Speak()
    {
        Console.WriteLine("Dog barks");
    }
}

Agar tumhare paas ek Dog object ho lekin use Animal type ke reference se reference kiya ho, to Speak() method dog ke version ko call karega.

1.4. Object Lifetime

C# mein objects ko automatically Garbage Collector (GC) ke dwara create aur destroy kiya jata hai. GC memory manage karta hai aur un objects ko free kar deta hai jo ab referenced nahi hote. Types of Objects:

  • Reference Types (Classes, Arrays, Strings): Heap pe stored hote hain aur GC ke through manage kiye jaate hain.

  • Value Types (int, double, struct): Stack pe stored hote hain.

GC automatic run hota hai aur memory reclaim karta hai, lekin tum apni taraf se object lifetime control kar sakte ho using finalizers ya IDisposable interface implement karke.

Example:

class Test
{
    static void Main()
    {
        Test obj = new Test();
        // After this, obj is eligible for GC if no longer referenced.
    }
}

1.5. Components and Modules

Components ek self-contained, reusable units of functionality hoti hain. Modules wo hote hain jo related components ka group hote hain. Yeh terms large software systems ko chhote aur manageable pieces mein organize karne mein madad karti hain.

Example:

  • Component: Ek authentication ka class library jo alag-alag applications mein reuse ho sakta hai.

  • Module: Ek set of components jo user authentication, logging aur error management handle karta hai.

Use in C#:

  • Assemblies: Components ko assemblies mein package kiya jata hai jo DLLs ya EXEs ho sakte hain.

  • Namespaces: C# mein components ko logically organize karne ke liye namespaces use hote hain, jaise System.Collections.Generic jo collection classes ko define karta hai.

1.6. Windows Forms

Windows Forms ek GUI framework hai jo C# mein desktop applications build karne ke liye use hota hai. Yeh drag-and-drop approach ko use karta hai user interface design karte waqt, jisse graphical elements like buttons, textboxes aur menus ko easily develop kiya ja sakta hai.

Key Components:

  • Controls: UI elements jaise buttons, labels, aur textboxes.

  • Events: Actions jaise button clicks ya key presses jo functions ko trigger karte hain.

  • Form: Application ka main window.

Example:

public class MyForm : Form
{
    public MyForm()
    {
        Button btn = new Button();
        btn.Text = "Click Me";
        btn.Click += new EventHandler(Button_Click);
        Controls.Add(btn);
    }

    private void Button_Click(object sender, EventArgs e)
    {
        MessageBox.Show("Button clicked!");
    }
}

1.7. Interface

C# mein interface ek contract define karta hai jo methods (implementation ke bina) ka hota hai, jise class ko implement karna padta hai. Interfaces loose coupling ko promote karte hain, jisme class ko specific base class ki jagah behaviors implement karne ka option milta hai.

Key Points:

  • Multiple Inheritance: C# mein ek class multiple interfaces ko implement kar sakti hai, jo class ko multiple behaviors inherit karne ka option deta hai.

  • Interface vs Abstract Class: Interface sirf abstract hota hai, jabki abstract class concrete aur abstract methods dono ko implement kar sakta hai.

Example:

public interface IDriveable
{
    void Drive();
}

public class Car : IDriveable
{
    public void Drive()
    {
        Console.WriteLine("Car is driving");
    }
}

1.8. Cloneable Objects

C# mein objects ko cloneable banaya ja sakta hai agar tum ICloneable interface implement karo. Isse tum Clone() method ka use kar ke object ka shallow ya deep copy bana sakte ho.

  • Shallow Clone: Sirf object ko copy kiya jata hai, references ko nahi.

  • Deep Clone: Ek naya instance create kiya jata hai aur saare referenced objects bhi copy kiye jaate hain.

Example of ICloneable:

class Person : ICloneable
{
    public string Name { get; set; }
    public int Age { get; set; }

    public object Clone()
    {
        return new Person { Name = this.Name, Age = this.Age };
    }
}

1.9. Comparable Objects

Agar object ko comparable banana hai to usse IComparable<T> interface implement karna padta hai. Yeh tumhe define karne ka option deta hai ki tumhare objects kaise compare honge using CompareTo method.

Example:

class Person : IComparable<Person>
{
    public string Name { get; set; }

    public int CompareTo(Person other)
    {
        return string.Compare(this.Name, other.Name);
    }
}

1.10. Collections and Namespaces

C# mein collections objects ka group hoti hain, jaise arrays, lists, dictionaries, aur queues. Yeh collections alag-alag namespaces mein organized hoti hain, jaise System.Collections aur System.Collections.Generic.

Common Collections:

  • List: Ek dynamic array jo automatically resize hota hai.

  • Dictionary<TKey, TValue: Key-value pairs ka collection.

  • Queue: FIFO (First-In-First-Out) collection.

  • Stack: LIFO (Last-In-First-Out) collection.

List<int> numbers = new List<int> { 1, 2, 3 };
numbers.Add(4);

2. Advanced Class Construction

2.1. Custom Indexer

Indexer ek object ko array ki tarah index karne ka option deta hai, jo custom behavior ke liye use kiya ja sakta hai.

class MyCollection
{
    private int[] data = new int[5];

    public int this[int index]
    {
        get { return data[index]; }
        set { data[index] = value; }
    }
}

2.2. Overloading Operators

C# mein tum operators ko overload kar sakte ho taaki unke liye custom behavior define kiya ja sake.

class Point
{
    public int X, Y;

    public static Point operator +(Point p1, Point p2)
    {
        return new Point { X = p1.X + p2.X, Y = p1.Y + p2.Y };
    }
}

2.3. Delegates

Delegate ek type hota hai jo specific parameter list aur return type ke methods ko reference karta hai. Yeh callback methods aur event handling ke liye commonly use hota hai.

delegate void PrintMessage(string message);

class Program
{
    static void Print(string message)
    {
        Console.WriteLine(message);
    }

    static void Main()
    {
        PrintMessage print = Print;
        print("Hello, World!");
    }
}

2.4. Events

Event ek tarika hota hai jisme ek class doosri classes ya objects ko kisi occurrence ke baare mein notify karti hai, jo observer pattern ko follow karta hai. Event delegates pe based hota hai.

public event EventHandler MyEvent;

void OnMyEvent()
{
    MyEvent?.Invoke(this, EventArgs.Empty);
}
PreviousUnit - I ( English - Version for exams )NextUnit - II (English Version - for papers)

Last updated 4 months ago