没有私有字段,可以直接使用属性吗?以下是高级编程中的例子:
using System;
using System.Collections.Generic;
using System.Text;namespace Wrox.ProCSharp.Generics
{
    public class Document : IDocument
    {
        public Document()
        {        }        public Document(string title, string content)
        {
            this.Title = title;
            this.Content = content;
        }
        public string Title {get; set;}
        public string Content {get; set;}    }
}

解决方案 »

  1.   

    一般设置私有字段,是这个类的一部分,属性用来提供访问私有字段的方法,同时可以设置是只能get还是只能set或都可以!
      

  2.   

    一般不是你着这么写的。
    一般是设置私有字段,在用属性对这个私有字段进行访问权限控制,get获得该字段的值,set赋值
      

  3.   

    这是另一个例子,好像这样已经成了约定俗成的规矩:using System;
    namespace Wrox.ProCSharp.Generics
    {
        public interface IDocument
        {
            string Title { get; set; }
            string Content { get; set; }
        }
    }
      

  4.   

    这个是接口!包含了属性声明,接口一般里面是抽象方法,然后由其他接口或类进行继承,然后实现方法!
    下面是参考
    http://msdn.microsoft.com/zh-cn/library/87d83y5b(VS.80).aspx
    http://software.ccidnet.com/art/322/20030311/40173_1.html
      

  5.   

    这好像是freamwork3.5新增加的功能,可以这样简写get,set方法,以前要比较麻烦。
      

  6.   

    谢谢shadow_20064104,你的提醒太好了,让我概念清楚了一些。
      

  7.   


    对,这个兄弟说的很明确了,我也跟着学习了!
    关键字是Interface ,这里的属性仅仅是定义而已
    如果要用,继承的时候必须实现。
      

  8.   

    Document执行了接口IDocument,是不是就没有私有字段了呢?
    public class Document : IDocument 请参考一楼和五楼的代码
      

  9.   

    这是C# 3.0的新语法,叫做自动属性...和.NET Framework并没有关系...要根据自己去看C# 3.0语言规范...