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

推荐订阅源

雷峰网
雷峰网
L
LangChain Blog
GbyAI
GbyAI
F
Fortinet All Blogs
腾讯CDC
Last Week in AI
Last Week in AI
A
About on SuperTechFans
J
Java Code Geeks
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
B
Blog
D
Docker
G
Google Developers Blog
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tailwind CSS Blog
宝玉的分享
宝玉的分享
U
Unit 42
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed

博客园 - 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 
*/