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.

3
  • First, thank you. Second, I want to create the dog variable in the scope of the if statement and not in outer scope. Commented Aug 18, 2011 at 20:10
  • @Michael you cannot do that in an if statement. The if has to have a bool result not an assignment. Jon Skeet provides some nice generic and lambda combinations you may which to consider as well. Commented Aug 18, 2011 at 20:13
  • if can have a bool result and an assignment. Dog dog; if ((dog = animal as Dog) != null) { // Use Dog } but that still introduces the variable in the outer scope. Commented Aug 24, 2011 at 17:36