获取,设置和C#.NET值关键字 [英] get,set and value keyword in c#.net
本文介绍了获取,设置和C#.NET值关键字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是值
这里的关键字,它是怎么分配的值 _num
?我是pretty的困惑,请给以下code中的说明。
私人诠释_num;
公众诠释NUM
{
得到
{
返回_num;
}
组
{
_num =价值;
}
}
公共无效的button1_Click(对象发件人,EventArgs的)
{
NUM = numericupdown.Value;
}
解决方案
在属性setter的背景下,值
关键字重新presents被分配的值的财产。它实际上是设置
访问的隐含参数,就好像是这样的声明:
私人诠释_num
公众诠释NUM
{
得到
{
返回_num;
}
集(int值)
{
_num =价值;
}
}
属性访问实际上是方法等同于:
公众诠释get_num()
{
返回_num;
}
公共无效set_num(int值)
{
_num =价值;
}
What is value
keyword here and how is it assigning the value to _num
? I'm pretty confused, please give the description for the following code.
private int _num;
public int num
{
get
{
return _num;
}
set
{
_num=value;
}
}
public void button1_click(object sender,EventArgs e)
{
num = numericupdown.Value;
}
解决方案
In the context of a property setter, the value
keyword represents the value being assigned to the property. It's actually an implicit parameter of the set
accessor, as if it was declared like this:
private int _num
public int num
{
get
{
return _num;
}
set(int value)
{
_num=value;
}
}
Property accessors are actually methods equivalent to those:
public int get_num()
{
return _num;
}
public void set_num(int value)
{
_num = value;
}
这篇关于获取,设置和C#.NET值关键字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文