惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
V
Visual Studio Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
MyScale Blog
MyScale Blog
Hugging Face - Blog
Hugging Face - Blog
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 叶小钗
博客园 - 聂微东
U
Unit 42
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
GbyAI
GbyAI
IT之家
IT之家
The GitHub Blog
The GitHub Blog
Stack Overflow Blog
Stack Overflow Blog
MongoDB | Blog
MongoDB | Blog
Y
Y Combinator Blog
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)

博客园 - James_Chen

SEO站内优化(On-page SEO) 一个逗号引发的IE7 Jquery Ajax失效 CSS IE6/IE7/IE8/FireFox CSS 兼容办法 hack - James_Chen Chromium书签同步无法连接到服务器的解决办法 jquery ajax 乱码解决 does not contain a definition for 80072745 80072efd 解决办法 FLASH ActionScript2.0 读取WebService数据 实现将dataset已有的一个datatable重新排序(转) ASP.NET程序中常用的三十三种代码 - James_Chen - 博客园 DataGridView 在程序集中找到无效的ServicedComponent派生类。 Cookie常用 - James_Chen - 博客园 regasm regsvcs区别 8004EOOF错误 - James_Chen - 博客园 给BindingNavigator加个保存按钮 DateSet和BindingNavigator合作的产物 Visual Studio 2005 中的 TableAdapter C#中计算两个时间的差
声明了属性后,可像使用类的字段那样使用这些属性。 - James_...
James_Chen · 2006-06-20 · via 博客园 - James_Chen

private int myVar;

public int MyProperty
{
get return myVar;}
set { myVar = value;}
}

这使得获取和设置属性值时都可以使用非常自然的语法,如以下语句中所示:

person.Name = "Joe";
person.Age 
= 99;



class Person
{
private string m_name = "N/A";
private int m_Age = 0;

// Declare a Name property of type string:
public string Name
{
get
{
return m_name;
}

set
{
m_name 
= value;
}

}


// Declare an Age property of type int:
public int Age
{
get
{
return m_Age;
}


set
{
m_Age 
= value;
}

}


public override string ToString()
{
return "Name = " + Name + ", Age = " + Age;
}

}


class TestPerson
{
static void Main()
{
// Create a new Person object:
Person person = new Person();

// Print out the name and the age associated with the person:
System.Console.WriteLine("Person details - {0}", person);

// Set some values on the person object:
person.Name = "Joe"
person.Age 
= 99;
System.Console.WriteLine(
"Person details - {0}", person);

// Increment the Age property:
person.Age += 1;
System.Console.WriteLine(
"Person details - {0}", person);
}

}




/*输出
Person details - Name = N/A, Age = 0
Person details - Name = Joe, Age = 99
Person details - Name = Joe, Age = 100 
*/