小编Dav*_*ave的帖子

为什么委托中"this"指针为空?

我有以下代码(为清楚起见,删除了详细信息):

    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)

.net c#

7
推荐指数
2
解决办法
1213
查看次数

标签 统计

.net ×1

c# ×1