zoukankan      html  css  js  c++  java
  • List 集合的交集

       private void Test()
            {
                List<string> lsA = new List<string>();
                lsA.Add("A");
                lsA.Add("B");
                lsA.Add("C");
                lsA.Add("D");
    
                List<string> lsB = new List<string>();
                lsB.Add("C");
                lsB.Add("D");
                lsB.Add("E");
                lsB.Add("F");
    
    
                List<string> lsC = new List<string>();
                lsC.Add("D");
                lsC.Add("G");
                lsC.Add("H");
    
                IEnumerable<string> lstNew = null;
                lstNew = lsA.Intersect(lsB, StringComparer.OrdinalIgnoreCase);
    
                lstNew = lstNew.Intersect(lsC, StringComparer.OrdinalIgnoreCase);
                //也可以连着写,如下
                //   lstNew = lsA.Intersect(lsB, StringComparer.OrdinalIgnoreCase).Intersect(lsC, StringComparer.OrdinalIgnoreCase);
    
    
                //下面这种方式也可以
                // IEnumerable<string> lsIntersect = Enumerable.Intersect(lsA, lsB);
    
                
                string str = string.Empty;
                if (lstNew != null && lstNew.Count<string>() > 0)
                {
                    foreach (string c in lstNew)
                    {
                        str += c;
                    }
                }
                MessageBox.Show(str);
            }
  • 相关阅读:
    es6 类
    set/ weakset/ map/ weakmap
    async/await
    生成函数
    数组的操作
    解决异步(重点promise函数)
    迭代器
    遍历
    symbol 数据类型
    es6.代理 proxy
  • 原文地址:https://www.cnblogs.com/quietwalk/p/3531704.html
Copyright © 2011-2022 走看看