C# lambda foreach

List xmlItemList

Dictionary itemQtyDic = new Dictionary();

xmlItemList.ForEach(x =>
            {
                if (!string.IsNullOrEmpty(x[quantityName]?.InnerText))
                    itemQtyDic.Add(x[XML_ITEM_LINENUMBER].InnerText + "|" + x[BSP_FIELD_CUSTOMER_NUMBER].InnerText
                    , Convert.ToInt32(x[quantityName].InnerText));
            });

 

xmlItemList is a List which is XMlNode, we need to check x[quantityName] whether is null, if not, we need to add key and value to a dictionary.

你可能感兴趣的:(C#,C#,lambda,foreach)