是條件請查看以下示例?:冗餘條件檢查5
public class MyClass {
public bool MyProperty { get; set; }
public void DoSomething(bool newValue) {
// R# says: redundant condition check before assignment
// on the following line:
if (MyProperty != newValue) { // <======
MyProperty = newValue;
}
}
}
我知道,無論哪種方式MyProperty
將被設置爲newValue
在真是多餘,而且是檢查多餘?
在Adobe Flex中,getter is called implicitly by the VM即使沒有進行明確的檢查,也會在調用setter時調用getter is called implicitly by the VM。最終結果是,在分配結果進行兩次檢查之前進行檢查,一次顯式檢查和一次隱式檢查,從而導致冗餘檢查。在C#中有類似的事情嗎?
對我來說,這是圍繞Windows窗體`TopMost`屬性,它確實有副作用。有關不可變價值的很好的觀點。 – 2011-01-21 16:02:00