tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Strongly typed generic object in C#

16 Jun 2026 1 mins .NET, C#

Because sometimes you just need bit more type safety.

public class Object<T> : Object
{ }

Isn’t it beautiful? And useless… But I think I can do better, it feels like I’m missing something.

public class Object<T> : Object
    where T : Object<T>
{ }

That’s better. But… What about nulls. We know nulls are source of so many problems.

public class Object<T> : Object
    where T : notnull, Object<T>
{ }

Ahhh. Now it’s how I like it. Completely utterly useless. 😎

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.