Reputation: 33
I'm trying to convert the following VB.NET code into C#:
stacks.AddRange(
From bin In UpstreamBinNames
Where bin <> BinName(BeforeTrack)
Select binWall = ConfigGlobals.Bins(bin).Wall
From aStack In binWall.Stacks Select aStack)
I get the first part, but the last half becomes confusing. How can i rewrite this without LINQ?
Thanks.
Upvotes: 3
Views: 88
Reputation: 16956
How about this? Use SelectMany
to pick all stacks.
stacks.AddRange(UpstreamBinNames
.Where(bin=> bin != BinName(BeforeTrack))
.SelectMany(s=>ConfigGlobals.Bins(bin).Wall.Stacks)
);
Upvotes: 2
Reputation: 125620
Would be something like this (pardon using C#, but you should get the idea):
foreach(var bin in UpstreamBinNames)
{
if(bin != BinName(BeforeTrack)
{
var binWall = ConfigGlobals.Bins(bin).Wall;
foreach(var aStack in binWall.Stacks)
{
stacks.Add(aStack);
}
}
}
Upvotes: 3
Reputation: 27357
Something like:
var tmpStacks = new List<Stack>();
foreach(var bin in UpstreamBinNames)
{
if (bin != BinName(BeforeTrack))
{
var binWall = ConfigGlobals.Bins(bin).Wall;
foreach (var aStack in binWall.Stacks)
tmpStacks.Add(aStack);
}
}
stacks.AddRange(tmpStacks);
Upvotes: 2