The .NET Base Class Library (BCL)

Lesson 5: The .NET Base Class Library (BCL)

In this lesson, you will discover the Base Class Library (BCL), the set of core libraries that provides fundamental building blocks for all .NET applications.


📚 What is the BCL?

The BCL is a collection of classes, interfaces, and types that cover essential functionality, including:

  • Basic types (strings, numbers, dates).
  • Collections and generics.
  • File I/O.
  • Networking.
  • Reflection and metadata.

These libraries are part of System.* namespaces.


🧩 Key Namespaces in the BCL

Here are some important namespaces you will use often:

  • System: Core types like String, Int32, DateTime.
  • System.Collections: Non-generic collections.
  • System.Collections.Generic: Generic collections like List<T> and Dictionary<TKey, TValue>.
  • System.IO: Reading and writing files and streams.
  • System.Net: Networking and HTTP communication.
  • System.Linq: Language Integrated Query (LINQ) support.

🔧 Example: Working with Collections

Here is an example of using a generic list:


using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        List fruits = new List();
        fruits.Add("Apple");
        fruits.Add("Banana");
        fruits.Add("Orange");

        foreach (var fruit in fruits)
        {
            Console.WriteLine(fruit);
        }
    }
}

This example demonstrates the power of the BCL collections.


📁 Example: Reading a Text File

Reading all lines from a file with System.IO:


using System;
using System.IO;

class Program
{
    static void Main()
    {
        string[] lines = File.ReadAllLines("example.txt");
        foreach (string line in lines)
        {
            Console.WriteLine(line);
        }
    }
}


🔍 Reflection

The BCL includes reflection, which allows inspecting metadata:


using System;
using System.Reflection;

class Program
{
    static void Main()
    {
        Type type = typeof(string);
        Console.WriteLine("Methods in String class:");
        foreach (var method in type.GetMethods())
        {
            Console.WriteLine(method.Name);
        }
    }
}


📝 Summary

The BCL is an essential part of .NET, providing reusable, consistent APIs that make development faster and more productive.


✅ Next Lesson

Lesson 6: Language Integrated Query (LINQ)

تعليقات

المشاركات الشائعة من هذه المدونة

Entity Framework - ما هو ORM؟ ونبذة عن Dapper وNHibernate

1.1 SQL Introduction

Entity Framework - مقدمة عن Entity Framework