title: How can I declare some variables in a conditional statement?
body: <p>I'm studying some open source codes and converting them from visual studio version 2017 to 2015.</p>
  <p>But I don't know how to convert any code.</p>
  <p>I think there is a problem with the declaration of local variables in conditional statement.</p>
  <p>This code</p>
  <pre><code>public static void ManageToolActivation(this IMachineElementViewModel vm, bool value)
          {
  
              if (vm is ToolHolderViewModel thvm)
              {
                  thvm.ActiveTool = value;
              }
              else
              {
                  foreach (var item in vm.Children)
                  {
                      var child = item as MachineElementViewModel;
  
                      child.ManageToolActivation(value);
                  }
              }
          }
  </code></pre>
  <p>causes</p>
  <blockquote>
  <p>The name 'thvm' does not exist in the current context</p>
  </blockquote>
  <p><code>ToolHolderViewModel</code> is a name of other project(class).</p>
  <p>It works in visual studio 2017 but not in visual studio 2015. I think there's a problem with declaring variables in conditional statements.</p>
  <p>How can I modify this code to work?</p>