我有三个属性的以下类。如何根据c#中的条件显示和隐藏属性值和值#
public class Item
{
public float a { get; set; }
public float b { get; set; }
public float c { get; set; }
}
下面是我需要返回类型的Item不应该包含默认值或空值的方法。我怎样才能做到这一点。
class Program
{
static void Main(string[] args)
{
List<Item> callingprogram = CallIngprogram1();
callingprogram2(callingprogram);
}
private static List<Item> callingprogram2(List<Item> paramss)
{
if (paramss[0].c == 0.0)
{
// return the list which should not contain the property C. IF the value is null or default value that property value should not return
}
return null;
}
private static List<Item> CallIngprogram1()
{
List<Item> list = new List<Item>();
list.Add(new Item
{
a = 1,
b = 3
// c value is not assign so it contain the default value
});
return list;
}
}
假设我给所有三个属性赋值,所有三个属性应该返回。如果我没有给任何属性名称赋值以及值不应该返回。
你的问题就没有意义了。默认值与为属性显式赋值'0.0'没有什么不同。 –
我的担心是如果我为a和b属性赋值,返回类型应该只包含a和b参数。因为它有默认值,所以在返回值中不需要c。 –