Is there any practical difference between the extension method on <T> or on the object?
Is there any practical difference between the two extension methods?
class Extensions
{
public static void Foo<T>(this T obj) where T : class { ... }
public static void Foo(this object obj) { ... }
}
I fidgeted in Extension Overflow , and I came across the first form that I had not used before. Curious what the difference is.
+5
1 answer
Extension methods on Objectalso apply to value types. (And they will be in the box on call, reducing performance)
Extension methods on <T>but without where T : classwill also work with value types, but will not put them.
, <T> typeof(T), .
,
someButton.Extension();
someButton.Extension<Control>();
someButton.Extension<Object>();
+10