Wil*_*ill 13 c# generics extension-methods
可能重复:
C# - 通用扩展方法如何为通用
类型类编写C#扩展方法
是否可以为泛型类声明扩展方法?
public class NeedsExtension<T>
{
public NeedsExtension<T> DoSomething(T obj)
{
// ....
}
}
Run Code Online (Sandbox Code Playgroud)
Sta*_* R. 34
扩展任何课程
public static class Extensions
{
public static T DoSomething<T>(this T obj)
{
//...
}
}
Run Code Online (Sandbox Code Playgroud)
扩展特定的泛型类
public static NeedExtension<T> DoSomething<T>(this NeedExtension<T> obj)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
Asa*_*sad -5
public static class NeedsExtension<T>
{
public static string DoSomething <T>(this MyType<T> v)
{ return ""; }
// OR
public static void DoSomething <T>(this MyType<T> v)
{
//...
}
}
Run Code Online (Sandbox Code Playgroud)