Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In general, yes, C# is a bit more verbose than a dynamic / lossely typed language. The same is true of Java. Looking at your specific examples ...</p> <pre><code>private bool isChecked(CheckBox control) { return control != null &amp;&amp; control.IsChecked != null &amp;&amp; control.IsChecked.HasValue &amp;&amp; (bool)control.IsChecked; } </code></pre> <p>A couple of points ... the following two checks are equivalent:</p> <pre><code>control.IsChecked != null control.IsChecked.HasValue </code></pre> <p>The IsChecked property is a Nullable type. As you are new to C# I would recommend reading up on value types vs. reference types. Once you have the hang of that, you can find out how the Nullable type can be used to wrap a value type in order to assign a null value to it. The page linked below explains why the twp statements above are equivalent:</p> <p><a href="http://msdn.microsoft.com/en-us/library/2cf62fcy%28VS.80%29.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/2cf62fcy%28VS.80%29.aspx</a></p> <p>Secondly, why are you checking that control!=null ? In typical scenarious you create controls in XAML on your Window or UserControl, identifying via the x:Name attribute. In this case you can rely on the control being present in your UI and drop this check.</p> <p>Your other two checks are necessary ;-) </p> <p>Good idea placng these in a method that you can re-use. You can also 'extend' the langauge by creating extension methods, e.g</p> <pre><code>private bool IsChecked(this CheckBox control) { return control.IsChecked.HasValue &amp;&amp; (bool)control.IsChecked; } // calls the extension method above. myCheckBox.IsChecked() </code></pre> <p>Hoep that helps.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload