I am trying to return a value (a.tnAddress
) from a custom class based on a lookup (foreach
loop). Depending on the type of transaction, I will need to do the foreach
loop based on different properties (sExecID
, iMsgSeqNum, or
sClOrderID). I prefer to not have 3 different
foreach` loops just but I am not sure how else to re-write this.
Keep in mind that the code is working fine; I just want to simplify it.
private TreeNode GetNodeAddress(cls_Transactions trPassedInTransaction)
{
switch (trPassedInTransaction.sMessageType)
{
case "Q":
case "8b":
foreach (cls_Transactions a in cls_GlobalVariables.transList)
{
if (trPassedInTransaction.sExecID == a.sExecID)
{
return a.tnAddress;
}
}
break;
case "3":
foreach (cls_Transactions a in cls_GlobalVariables.transList)
{
if (trPassedInTransaction.iMsgSeqNum == a.iMsgSeqNum)
{
return a.tnAddress;
}
}
break;
default:
foreach (cls_Transactions a in cls_GlobalVariables.transList)
{
if (trPassedInTransaction.sClOrderID == a.sClOrderID)
{
return a.tnAddress;
}
}
break;
}
return null;
}