Getting Started with ASP.NET Classes and Class Libraries

Last Updated: Nov 08, 2025
7 min read
Legacy Archive
Legacy Guidance: This article preserves historical web development content. For modern .NET 8+ best practices, visit our Tutorials section.

In object-oriented programming, a class is a data structure that describes an object or data member. The .NET Framework has an extensive set of class libraries such as data access, XML support, directory services, regular expressions, and queuing support.

The data access class library provides classes to connect to SQL Server or any OLEDB provider. The XML support class library has capabilities that go beyond what MSXML offers. The directory services library accesses Active Directory and LDAP using ADSI. The regular expression library supports Perl 5 patterns and much more.

CLR Base Class Libraries

All the class libraries mentioned above use the CLR base class libraries for common functionality. These base class libraries can be divided into six main categories, each serving specific purposes in application development.

Collections

Collections preserve a set of values or objects in memory. The three commonly used collection classes are ArrayList, HashTable, and SortedList. The System.Collections namespace is used to derive collection classes.

Using ArrayList
using System;
using System.Collections;

// Create ArrayList
ArrayList numbers = new ArrayList();
numbers.Add(10);
numbers.Add(20);
numbers.Add(30);

// Iterate through collection
foreach (int num in numbers)
{
    Console.WriteLine(num);
}

// Access by index
Console.WriteLine("First item: " + numbers[0]);
Using HashTable
using System.Collections;

// Create HashTable for key-value pairs
Hashtable employees = new Hashtable();
employees.Add("E001", "John Smith");
employees.Add("E002", "Jane Doe");
employees.Add("E003", "Bob Johnson");

// Access by key
string name = (string)employees["E001"];
Console.WriteLine("Employee E001: " + name);

// Check if key exists
if (employees.ContainsKey("E002"))
{
    Console.WriteLine("Found employee E002");
}

Thread Support

Thread support provides fast, efficient, and multithreaded applications. It uses the System.Threading namespace to create and manage threads, allowing your application to perform multiple operations simultaneously.

Basic Threading Example
using System;
using System.Threading;

class Program
{
    static void WorkerMethod()
    {
        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("Worker thread: " + i);
            Thread.Sleep(100);
        }
    }
    
    static void Main()
    {
        Thread worker = new Thread(WorkerMethod);
        worker.Start();
        
        for (int i = 0; i < 5; i++)
        {
            Console.WriteLine("Main thread: " + i);
            Thread.Sleep(100);
        }
        
        worker.Join();
    }
}

Code Generation

Code generation converts ASP.NET pages into classes and generates source files in multiple languages. The System.CodeDOM namespace is used to derive code generation classes, enabling dynamic code creation and compilation at runtime.

Input/Output Operations

The IO classes work with files and all other stream types. System.IO namespace provides classes for reading from and writing to files, working with directories, and handling various stream types.

File Operations
using System;
using System.IO;

// Write to file
string content = "Hello, World!";
File.WriteAllText("sample.txt", content);

// Read from file
string fileContent = File.ReadAllText("sample.txt");
Console.WriteLine(fileContent);

// Check if file exists
if (File.Exists("sample.txt"))
{
    Console.WriteLine("File exists");
}

// Get file info
FileInfo info = new FileInfo("sample.txt");
Console.WriteLine("Size: " + info.Length + " bytes");
Console.WriteLine("Created: " + info.CreationTime);

Reflection

Reflection provides support for loading assemblies, inspecting types within assemblies, and creating instances of types. It uses the System.Reflection namespace and is powerful for building dynamic applications, tools, and frameworks.

Using Reflection
using System;
using System.Reflection;

class Sample
{
    public int Number { get; set; }
    public string Name { get; set; }
    
    public void Display()
    {
        Console.WriteLine($"{Name}: {Number}");
    }
}

class Program
{
    static void Main()
    {
        // Get type information
        Type type = typeof(Sample);
        
        // Get properties
        PropertyInfo[] properties = type.GetProperties();
        foreach (PropertyInfo prop in properties)
        {
            Console.WriteLine("Property: " + prop.Name);
        }
        
        // Get methods
        MethodInfo[] methods = type.GetMethods();
        foreach (MethodInfo method in methods)
        {
            Console.WriteLine("Method: " + method.Name);
        }
        
        // Create instance dynamically
        object obj = Activator.CreateInstance(type);
        PropertyInfo nameProp = type.GetProperty("Name");
        nameProp.SetValue(obj, "Test");
    }
}

Security

Security classes are used extensively to build security strategies for ASP.NET pages. The System.Security namespace provides base services such as authentication, authorization, permission sets, policies, and cryptography. These classes help protect your applications from unauthorized access and ensure data integrity.

Basic Cryptography Example
using System;
using System.Security.Cryptography;
using System.Text;

class Program
{
    static void Main()
    {
        string original = "Sensitive Data";
        
        // Create hash
        using (SHA256 sha256 = SHA256.Create())
        {
            byte[] bytes = Encoding.UTF8.GetBytes(original);
            byte[] hash = sha256.ComputeHash(bytes);
            
            string hashString = BitConverter.ToString(hash);
            Console.WriteLine("Original: " + original);
            Console.WriteLine("Hash: " + hashString);
        }
    }
}

Finding Classes

There are numerous classes in ASP.NET. If you want to find and locate a particular class, you can use the WinCV tool. This file is located in the Framework SDK Bin directory at C:\Program Files\Microsoft.Net\FrameworkSDK\Bin. You can open this file from the Run command to browse through available classes and their members.

The WinCV tool provides a graphical interface to explore the .NET Framework class library, view class hierarchies, and examine members of each class. This makes it easier to discover the right classes for your development needs.

FAQ

What's the difference between ArrayList and HashTable collections?

ArrayList stores items in ordered sequence and accesses them by index, while HashTable stores key-value pairs and accesses them by key. Use ArrayList when you need ordered lists, and HashTable when you need fast lookups by unique keys.

When should I use System.Reflection in my applications?

Use System.Reflection when you need to load assemblies at runtime, inspect types dynamically, or create instances without knowing the exact type at compile time. This is useful for plugin systems, serialization, or building development tools.

How do I find specific classes in the .NET Framework?

You can use the WinCV tool located in the Framework SDK Bin directory to browse and search for classes. Modern alternatives include Visual Studio's Object Browser or online documentation at docs.microsoft.com.

Back to Articles