对于同一属性是无法定义不同的访问性的。一般情况下,我们定义一个属性会对应到一个私有成员变量,我认为可以通过两个属性对应到同一个私有成员,一个属性实现get,另一个实现set,这样应该可以实现你的需求。For example:private string _x;public string GetX
{
    get { return _x; }
}protected string SetX
{
    set { _x = value; }
}

解决方案 »

  1.   

    //试了一下,上述方法不行,关注!测试代码如下
    public class B
    {
    private string _x; public string GetX
    {
    get { return _x; }
    } protected string SetX
    {
    set { _x = value; }
    } }
    public class C:B
    {

    }
    //
    B b=new B();
    C c=new C();
      

  2.   

    Aloneco(清影)的想法我觉得很有创意,我就没想到,但我觉得有点累赘之感,还不如用方法。
      

  3.   

    我也试了一下,完全可行。测试如下:1、先定义类B和其子类C(并在C中设置属性值)
    public class B
    {
    private string _x; public string GetX
    {
    get { return _x; }
    } protected string SetX
    {
    set { _x = value; }
    } public B()
    {
    }
    } public class C:B
    {
    public C()
    {
    this.SetX = "Hello World";
    }
    }2、然后在一个窗口的按钮的单击事件中创建C的实例,并将_x的值赋给该按钮的Text属性。private void button1_Click(object sender, System.EventArgs e)
    {
    C _c = new C();
    this.button1.Text = _c.GetX;
    }3、编译运行,结果正确。
      

  4.   

    属性是可以分为 public 或 protected 的。
    如:protected bool ChildControlsCreated {get; set;}看SDK中随便哪一个类,几乎你都能找到 Public properties 和 Protected Poperties 两部分。
      

  5.   

    目前C#不支持。
    可能的方法是:直接使用MSIL编码。
    例如,先用C#编写整个Assembly的代码,然后用ildasm.exe导出IL,编辑IL文件,给get/set方法赋予不同的访问属性,然后用ilasm.exe重新汇编成.dll或者exe文件。