我有以下代码(为清楚起见,删除了详细信息):
private abstract class Base<TResult> {
private readonly System.Func<TResult> func = null;
protected Base(System.Func<TResult> func) {
this.func = func;
}
public TResult Execute() {
return this.func();
}
}
private class Derived : Base<bool> {
public Derived(bool myValue) : base(delegate() { return this.MyValue(); }) {
this.myValue = myValue;
}
private bool myValue = false;
private bool MyValue() {
return this.myValue; // The "this" pointer is null here...
}
}
Derived d = new Derived(true);
bool result = d.Execute(); // This results …Run Code Online (Sandbox Code Playgroud)