I’m tracing some code, and a list is sent to the below, to remove certain items from the list.
Is this the proper way to use the goto? Is it even necessary? Wouldn’t you just edit the second if to be an else if, and continue processing the list without the need for a goto? (This is the first time I’ve ever seen goto outside of BASIC.)
public static IList<ClientEntity> FilterNoNeedSendBackToClients(IList<ClientEntity> src)
{
if (src == null)
return null;
checkAB01:
for (int i = 0; i < src.Count; i++)
{
ClientEntity info = src[i];
if (info.ProductNumber != null && info.ProductNumber.ToLower().Trim().Length > 0
&&
info.CancelledByReliantSyncAB01 != null && info.CancelledByReliantSyncAB01.Value == true
)
{
src.Remove(info);
goto checkAB01;
}
if ((info.PartnerContract == null || info.PartnerContract.Trim().Length == 0)
&&
(info.ProductNumber == null || info.ProductNumber.Trim().Length == 0))
{
src.Remove(info);
goto checkAB01;
}
}
return src;
}
How about LINQ?