我有三個屬性的以下類。如何根據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。 –