我有一個包含這樣發現如果一個類中的所有屬性都一樣
public MyClass
{
public MyClass(double all = 0)
{
Top = Bottom = Left = Right = all;
}
public MyClass(double lr = 0, double tb = 0)
{
Top = Bottom = tb;
Left = Right = lr;
}
public MyClass(double l = 0, double r = 0, double t = 0, double b = 0)
{
Top = t;Bottom = b;Left = l;Right = r;
}
public double Top {get; private set;}
public double Bottom {get; private set;}
public double Left {get; private set;}
public double Right {get; private set;}
}
4個屬性有一個簡單的方法來檢查,如果所有屬性具有相同的值的簡單類?我寧願不使用if (Top == Bottom) && (Top == Left) ...
,因爲它有點凌亂恕我直言。可以在LINQ中完成嗎?
爲什麼「做你想做的事情」是混亂的?任何其他解決方案,特別是添加LINQ時,只會變得更加混亂。 – CodeCaster