如何检查"如果"c#.net中的属性的条件? [英] How to check " if " condition in a property in c#.net?
本文介绍了如何检查"如果"c#.net中的属性的条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在c#.net中的属性中检查"if"条件?
How to check " if " condition in a property in c#.net?
推荐答案
您可以执行此操作-
You can do this -
public int myProp
{
get { if (condition) { return a; } else { return b;} }
set
{
a = value;
}
}
使用下面的代码,其中包含使用C#的属性中的条件.
Use following code that contains if conditions in properties using C#
private double seconds;
public double Hours
{
get
{
if (seconds == 3600)
{
return 100;
}
else
{
return seconds / 3600;
}
}
set
{
if (seconds == 3600)
{
seconds = 100;
}
else
{
seconds = value * 3600;
}
}
}
这篇关于如何检查"如果"c#.net中的属性的条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文