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
  • Object Serialization and Remoting
  • System.IO Namespace
  • Serialized Object Persistence and Formatters
  • Remoting
  • ADO.NET
  • Connected and Disconnected Scenarios
  • Key ADO.NET Objects
  • C# Windows Forms for Data Control
  • Key Controls for Data Control
  • ADO.NET in Windows Forms
  • Summary
  1. .NET Framework Notes
  2. .NET Framework Syllabus

Unit - IV ( English Version )

Object Serialization and Remoting

Serialization and remoting in .NET allow objects to be stored, transmitted, and reconstructed in different environments. Serialization converts an object into a format that can be saved or transmitted, while remoting enables communication between applications.

System.IO Namespace

The System.IO namespace provides types for reading, writing, and managing data streams and files.

  1. Streams:

    • A Stream is an abstract class used to transfer data.

    • Common streams:

      • FileStream: Reads and writes data to files.

      • MemoryStream: Stores data in memory.

      • NetworkStream: Communicates over a network.

  2. TextWriter and TextReader:

    • TextWriter: Writes text data to a stream (e.g., StreamWriter).

    • TextReader: Reads text data from a stream (e.g., StreamReader).

  3. BinaryWriter and BinaryReader:

    • BinaryWriter: Writes data in binary format to a stream.

    • BinaryReader: Reads binary data from a stream.

    Example of Binary Read/Write:

    using (BinaryWriter writer = new BinaryWriter(File.Open("data.bin", FileMode.Create)))
    {
        writer.Write(42);
        writer.Write("Hello");
    }
    
    using (BinaryReader reader = new BinaryReader(File.Open("data.bin", FileMode.Open)))
    {
        Console.WriteLine(reader.ReadInt32());
        Console.WriteLine(reader.ReadString());
    }

Serialized Object Persistence and Formatters

Serialization converts an object into a byte stream for storage or transmission, and deserialization reconstructs the object from the byte stream.

  1. Types of Serialization:

    • Binary Serialization: Uses BinaryFormatter for compact, efficient storage.

    • XML Serialization: Converts objects into XML format using XmlSerializer.

    • JSON Serialization: Converts objects into JSON using JsonSerializer.

  2. BinaryFormatter Example:

    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
    
    BinaryFormatter formatter = new BinaryFormatter();
    using (FileStream fs = new FileStream("objectData.bin", FileMode.Create))
    {
        MyClass obj = new MyClass { Id = 1, Name = "Test" };
        formatter.Serialize(fs, obj);
    }
    
    using (FileStream fs = new FileStream("objectData.bin", FileMode.Open))
    {
        MyClass obj = (MyClass)formatter.Deserialize(fs);
    }

Remoting

Remoting enables communication between different application domains, processes, or machines.

  1. Remoting Basics:

    • Uses objects like MarshalByRefObject to pass data between applications.

    • Communication can be achieved using channels like TCP or HTTP.

  2. Remoting Configuration:

    • Server-Side: Host an object in a remoting service.

    • Client-Side: Consume the object from the server.


ADO.NET

ADO.NET is the data access technology used to connect, retrieve, manipulate, and update data in databases. It supports both connected and disconnected scenarios.

Connected and Disconnected Scenarios

  1. Connected Scenario:

    • Requires an active connection to the database for performing operations.

    • Uses objects like SqlConnection, SqlCommand, and SqlDataReader.

  2. Disconnected Scenario:

    • Works with data stored locally in a DataSet.

    • Allows changes to be made offline and updated later.

Key ADO.NET Objects

  1. SqlConnection: Represents a connection to a database.

    SqlConnection conn = new SqlConnection("your_connection_string");
    conn.Open();
    conn.Close();
  2. SqlCommand: Represents a query or command executed on the database.

    SqlCommand cmd = new SqlCommand("SELECT * FROM Table", conn);
  3. SqlDataReader: Reads data row by row from a database.

    SqlDataReader reader = cmd.ExecuteReader();
    while (reader.Read())
    {
        Console.WriteLine(reader["ColumnName"]);
    }
  4. DataSet: An in-memory representation of data.

    DataSet ds = new DataSet();
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Table", conn);
    adapter.Fill(ds);
  5. SqlDataAdapter: Acts as a bridge between the database and the DataSet.


C# Windows Forms for Data Control

Windows Forms provides various controls for displaying and managing data.

Key Controls for Data Control

  1. GridView:

    • Displays data in a tabular format.

    • Data can be bound to a DataSource.

  2. DataSource:

    • Acts as a source of data for controls like GridView.

  3. DataBinding:

    • Links UI controls to data sources.

    • Example:

      textBox1.DataBindings.Add("Text", dataTable, "ColumnName");

ADO.NET in Windows Forms

  • Connect controls like GridView to a DataSet or DataTable.

  • Example:

    DataSet ds = new DataSet();
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Table", conn);
    adapter.Fill(ds);
    dataGridView1.DataSource = ds.Tables[0];

Summary

  • Object Serialization converts objects into a format for storage or transmission, using formatters like BinaryFormatter or JsonSerializer.

  • Remoting enables applications to communicate across processes or networks.

  • ADO.NET provides a robust way to connect to and manipulate databases, supporting both connected (SqlCommand, SqlDataReader) and disconnected (DataSet, SqlDataAdapter) operations.

  • C# Windows Forms allows data to be displayed and managed in a user-friendly interface using controls like GridView and databinding mechanisms.

PreviousUnit - IV ( Hinglish Version )NextUnit - V ( Hinglish Version )

Last updated 4 months ago