I am trying to gransp wether I can get big refactoring advantages out of learning LINQ.
How can LINQ improve this code, which is a real-world example that is representative for a lot of code in a project I work on:
foreach (SchemeElement elem in mainDiagram.Elements)
{
if (elem.SubType == EElemSubType.BusBar)
{
if (connPts.Busbars.ContainsKey(elem.ConnectionPointId))
{
if (!taAddrList.TAAddressList.ContainsKey(elem.Key))
{
taAddrList.TAAddressList.Add(elem.Key, new TAAddress());
}
taAddrList.TAAddressList[elem.Key] = connPts.Busbars[elem.ConnectionPointId];
}
} // if busbar
} // foreach element
For Clarity:
taAddrList.TAAddressList is of type Dictionary<ElemKey, TAAddress>
where ElemKey is a two-component type that consists of two int ID’s.
connPts.Busbars is of type Dictionary<int, TAAddress>
See for yourself: