我需要解释此代码 [英] i need explain of this code please
本文介绍了我需要解释此代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//宽度和高度的属性.
// Properties for Width and Height.
public double Width {
get { return pri_width; }
set { pri_width = value < 0 ? -value : value; }
}
推荐答案
这基本上只允许设置正宽度.任何负数都将转换为正数. Abs()函数也可以实现这一点.
http://msdn.microsoft.com/en-us/library/aa340192%28v = vs.71%29.aspx [ ^ ]
这里的功能相同:
This basically only allows setting a positive Width. Any negative number is converted to positive. The Abs() function would also achieve that.
http://msdn.microsoft.com/en-us/library/aa340192%28v=vs.71%29.aspx[^]
This here does the same:
public double Width
{
get { return pri_width; }
set { pri_width = Math.Abs(value); }
}
代码的简化版本
The simplified version of the code
public double Width
{
get
{
return pri_width;
}
set
{
if(value < 0)
{
pri_width = -value;
}
else
{
pri_width = value;
}
}
}
阅读三元运算符以取消原始代码.
如果您不了解属性:
Read ternary operator to unserstadn original code.
if you dont understand properties:
public double GetWidth
{
return pri_width;
}
public void setWidth(double value)
{
if(value < 0)
{
pri_width = -value;
}
else
{
pri_width = value;
}
}
免责声明:JF2015提供的解决方案是最好的.我只是在解释原始代码.
Discaimer: solution provided by JF2015 is the best one. I am just explaining the original code.
这篇关于我需要解释此代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文