C# - 改善的性能封装在这个例子吗? [英] C# - Improving encapsulation of property in this example?

查看:251
本文介绍了C# - 改善的性能封装在这个例子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道错误的set访问的可访问修饰符必须比属性或索引更严格。我也知道了解决方案。 。只是没有在这个非常特殊的情况下

I know of the error "The accessibility modifier of the set accessor must be more restrictive than the property or indexer". I also know the solution. Just not in this very specific case.

考虑这个例子:

    internal virtual bool IsFocused
    {
        get
        {
            return isFocused;
        }
        protected set
        {
            isFocused = value;
        }
    }
    private bool isFocused;



它显示错误。我只是不知道为什么。如何保护并不比内部不易进入的?这将是解决这一问题?我试图把内部保护代替,没有运气。

It shows the error. I just don't know why. How is "protected" not less accessible than internal? What would be the solution to this problem? I tried putting "internal protected" instead, without luck.

推荐答案

保护允许inherting类来访问它,而内部不 - 内部限制访问大会本身 - 见<一HREF =htt​​p://msdn.microsoft.com/en-us/library/7c5ka91b%28v=vs.80%29.aspx相对=nofollow> http://msdn.microsoft.com/en-us /library/7c5ka91b%28v=vs.80%29.aspx

protected allows an inherting class to access it while internal does NOT - internal restricts access to the assembly itself - see http://msdn.microsoft.com/en-us/library/7c5ka91b%28v=vs.80%29.aspx

这篇关于C# - 改善的性能封装在这个例子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆