title: How to get variable value outside IF ELSE
body: <p>I have a string array variable which will take filepaths based on condition but getting error as below:</p>
  
  <pre><code>if (chkIncludeSubFolders.Checked == true)
  {
      string[] filePaths = Directory.GetFiles(txtPath.Text, txtFormat.Text, SearchOption.AllDirectories);
  }
  else
  {
      string[] filePaths = Directory.GetFiles(txtPath.Text, txtFormat.Text, SearchOption.TopDirectoryOnly);
  }
  
  foreach (string item in filePaths)//Error: The name filePaths dose not exist in current context 
  {
      //my code
  }
  </code></pre>