C# lambda foreach

List<XmlNode> xmlItemList

Dictionary<string, int> itemQtyDic = new Dictionary<string, int>();

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.

猜你喜欢

转载自blog.csdn.net/u010081392/article/details/84342071