Jus*_*ner 15
你不能.您只能在定义类时覆盖方法.
最好的选择是使用适当的Func委托作为占位符,并允许调用者以这种方式提供实现:
public class SomeClass
{
public Func<string> Method { get; set; }
public void PrintSomething()
{
if(Method != null) Console.WriteLine(Method());
}
}
// Elsewhere in your application
var instance = new SomeClass();
instance.Method = () => "Hello World!";
instance.PrintSomething(); // Prints "Hello World!"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7055 次 |
| 最近记录: |