By Anoop Madhusudanan

As you may already know, C# compiler don’t support type inference for generic classes, but it supports type inference for generic methods. To illustrate the point, let us consider a very simple example.

As you can see, we are not specifying the type explicitly, while calling our IsGreaterThan method - it is inferred automatically by the compiler. That is simple, isn’t it? Now, things become a a bit more interesting when you combine Generic method type inference with extension methods. Have a look at this code, we just made our IsGreaterThan<T> method an extension method.

As you can see, we are still good - the compiler can still infer the types. And of course, you can leverage our IsGreaterThan against any IComparable implementation. Also, explore more back to basics posts.