B
Byron
I'm trying to get various LINQ results in the same var within a method, so I
can refer to the same var in the code that populates a listview. I tried the
clode below, but it obviously complained because of my reuse of "var
filteredECIDs =". I also tried initializing using var filteredECIDs = null,
followed by filteredECIDs = within the case statements, but it didn't like
that either.
Any help would be greatly appreciated.
switch (filter)
{
case "My Devices":
var filteredECIDs =
from e in this.MCU.ECIDs
where e.OwnerMAC == this.MCU.MAC
orderby e.Dist ascending
select new { e.Mac, e.Name, e.Dist, e.Direction,
e.Status };
break;
case "All Devices":
var filteredECIDs =
from e in this.MCU.ECIDs
orderby e.Dist ascending
select new { e.Mac, e.OwnerName, e.Name, e.Dist,
e.Direction, e.Status };
break;
....
}
foreach (var ecid in filteredECIDs)
{
ListViewItem i = new ListViewItem(ecid.Mac.ToString());
i.SubItems.Add(ecid.Status.ToString().Substring(0, 1));
i.SubItems.Add("ECID");
i.SubItems.Add(ecid.Name);
i.SubItems.Add(ecid.Dist.ToString());
i.SubItems.Add(ecid.Direction);
i.SubItems.Add(ecid.OwnerName);
lvECIDs.Items.Add(i);
}
can refer to the same var in the code that populates a listview. I tried the
clode below, but it obviously complained because of my reuse of "var
filteredECIDs =". I also tried initializing using var filteredECIDs = null,
followed by filteredECIDs = within the case statements, but it didn't like
that either.
Any help would be greatly appreciated.
switch (filter)
{
case "My Devices":
var filteredECIDs =
from e in this.MCU.ECIDs
where e.OwnerMAC == this.MCU.MAC
orderby e.Dist ascending
select new { e.Mac, e.Name, e.Dist, e.Direction,
e.Status };
break;
case "All Devices":
var filteredECIDs =
from e in this.MCU.ECIDs
orderby e.Dist ascending
select new { e.Mac, e.OwnerName, e.Name, e.Dist,
e.Direction, e.Status };
break;
....
}
foreach (var ecid in filteredECIDs)
{
ListViewItem i = new ListViewItem(ecid.Mac.ToString());
i.SubItems.Add(ecid.Status.ToString().Substring(0, 1));
i.SubItems.Add("ECID");
i.SubItems.Add(ecid.Name);
i.SubItems.Add(ecid.Dist.ToString());
i.SubItems.Add(ecid.Direction);
i.SubItems.Add(ecid.OwnerName);
lvECIDs.Items.Add(i);
}