Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

10
  • None that I know of. Any reason not to move Name up to Animal? Commented Aug 18, 2011 at 19:59
  • 23
    Just a note, code like can often be the result of breaking one of the SOLID Principles. The L - Liskov Substitution Principle. Not saying it's wrong to do what you are doing all the time, but might be worth thinking about. Commented Aug 18, 2011 at 20:03
  • please take note of what @ckittel is doing, you probably don't want to do this Commented Aug 19, 2011 at 12:43
  • In some languages, including C#, I believe, null is cast to false. So, if the result of the assignment is null, the statement evaluates to null which is then cast to false. That is why in some languages you can use if(var) {...} to execute code only if that variable is non-null. Generally, assigning to variables in an if statement is poo-pooed because it looks like a common error (typing = instead of ==). One used to be able to gain some (small) performance benefit from using an assignment in an if block, but many modern compilers will do optimizations like this for you. Commented Aug 23, 2011 at 18:02
  • 2
    @Solo no, null != false in C#; C# only allows actual bools or things implicitly convertible to bools in if conditions. Neither nulls nor any of the integer types are implicitly convertible to bools. Commented Aug 24, 2011 at 17:14