没有私有字段,可以直接使用属性吗?以下是高级编程中的例子:
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;} }
}
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;} }
}
一般是设置私有字段,在用属性对这个私有字段进行访问权限控制,get获得该字段的值,set赋值
namespace Wrox.ProCSharp.Generics
{
public interface IDocument
{
string Title { get; set; }
string Content { get; set; }
}
}
下面是参考
http://msdn.microsoft.com/zh-cn/library/87d83y5b(VS.80).aspx
http://software.ccidnet.com/art/322/20030311/40173_1.html
对,这个兄弟说的很明确了,我也跟着学习了!
关键字是Interface ,这里的属性仅仅是定义而已
如果要用,继承的时候必须实现。
public class Document : IDocument 请参考一楼和五楼的代码