C#  

Types of Classes in C# with Examples | Concrete, Static, Abstract, Sealed, and More

Types of Classes in C# with Examples (For .NET Framework)

C# is a powerful object-oriented programming language used in the .NET Framework. One of the key building blocks in C# is the class, and understanding the different types of classes in C# is essential for clean, maintainable, and scalable code.

In this guide, you'll learn the main types of C# classes, including concrete, static, abstract, sealed, partial, nested, generic, record, and anonymous classes, with examples and real-world use cases.

1. Concrete Class in C#

A concrete class is a regular class that can be instantiated and used to create objects.

public class Car { public void Drive() { Console.WriteLine("Driving..."); } }

Use when you need a complete class implementation.

More detailed: Types of Classes in C#

2. Static Class in C#

A static class in C#

  • Cannot be instantiated.
  • Can only contain static members.
  • It is automatically sealed.

public static class MathHelper { public static int Add(int a, int b) => a + b; }

Best for utility methods like Math, DateTime, etc.

Continue here: What is a Static Class in C#?

3. Abstract Class in C#

An abstract class

  • Cannot be instantiated.
  • Can include both abstract and non-abstract methods.
  • It must be inherited by another class.

public abstract class Animal { public abstract void Speak(); public void Eat() => Console.WriteLine("Eating..."); }

Use for base classes that require partial implementation.

Continue here: Abstract Class In C#

4. Sealed Class in C#

A sealed class prevents other classes from inheriting it.

public sealed class Logger { public void Log(string msg) => Console.WriteLine(msg); }

Use to stop further subclassing for security or performance.

Continue here: Sealed Class in C#

5. Partial Class in C#

Partial classes allow a class to be split across multiple files.

// File: Person1.cs public partial class Person { public string FirstName; } // File: Person2.cs public partial class Person { public string LastName; }

Useful in large projects or when using auto-generated code.

Continue here: Partial class in C#

6. Nested Class in C#

A nested class is defined inside another class.

public class Outer { public class Inner { public void Show() => Console.WriteLine("Inner class"); } }

Use to group related logic or helper classes inside another class.

Continue here: Nested class in C#

7. Generic Class in C#

A generic class allows type safety while remaining flexible.

public class Box<T> { public T Content; }

Used in collections like List<T>, Dictionary<TKey, TValue>.

Continue here: Generics in C#

8. Record Class (C# 9 and Above)

A record class (available in C# 9+ and .NET 5+) is:

  • Immutable by default.
  • Has built-in equality comparison.

public record Person(string FirstName, string LastName);

Ideal for data transfer objects (DTOs).

⚠️ Not available in .NET Framework unless upgraded to .NET 5+.

Continue here: Record class in C#

9. Anonymous Class in C#

An anonymous class is defined without an explicit type and is often used in LINQ or quick data groupings.

var person = new { Name = "John", Age = 30 };

Great for short-lived or temporary data structures.

Continue here: Anonymous Classes in C#

🔄 Summary Table

Class Type Instantiable Inheritable Use Case
Concrete ✅ Yes ✅ Yes Standard object with full definition
Static ❌ No ❌ No Helper methods, constants
Abstract ❌ No ✅ Yes Base for other classes to build on
Sealed ✅ Yes ❌ No Prevents inheritance
Partial ✅ Yes ✅ Yes Split class logic across files
Nested ✅ Yes ✅ Yes Internal class for encapsulated logic
Generic ✅ Yes ✅ Yes Type-safe reusable components
Record ✅ Yes ✅ Yes Immutable data models (C# 9+)
Anonymous ✅ Yes ❌ No Temporary, quick data object

✅ Conclusion

Understanding the different class types in C# helps you write better, more organized, and scalable code in the .NET Framework. Whether you're designing architecture or writing utility tools, picking the right class type is key.