How To Expose Variable to other If Statements

Trying to figure out how to expose a variable that I originally had in an If statement to another If statement. Please see original code:

 if (arr.Count > 0)
      var needIds = db.Table.Where(x => arr.Contains(x.Id));

 if (arrTwo.Count > 0)
      needIds = needIds.Where(x => arrTwo.Contains(x.Id));

I tried instantiating needIds before the two if statements like so:

var needIds = new Table();
var needIds = new List<Table>();
var needIds = new Solution.Folder.Table // I tried calling it directly

When I try to instantiate var needIds before the 1st if statement, I get the following error:

Cannot implicitly convert type 'System.Linq.IQueryableSolution.Folder.Table' to 'Solution.Folder.Table'. An explicit conversion exists (are you missing a cast?)

I am having a brain fart and cannot figure out how to properly instantiate needIds outside of the if statements so that I can utilize it across the method.

Thanks in advance.

- - Source
comments powered by Disqus