Skip to main content
2 of 2
added 329 characters in body
cassandrad
  • 3.6k
  • 31
  • 52

No, that's not possible, you have to use dynamic dispatching

public class C { public int DoWork<T>() { if (typeof(T) == typeof(int)) return DoWorkInt(); return 13; } private int DoWorkInt() { return 42; } } 

C# does not support explicit specialization; that is, a custom implementation of a template for a specific type.

From Differences Between C++ Templates and C# Generics

cassandrad
  • 3.6k
  • 31
  • 52