C#数组比较取值

            string strs = string.Empty;
            string[] strArray1 = { "a", "b", "c", "d" };
            string[] strArray2 = { "a", "b", "c", "f", "g" };

            Dictionary<string, string> map = new Dictionary<string, string>();
          
            for (int k = 0; k < strArray1.Length; k++)
            {
      map.Add(strArray1[k], "");
            }

            for (int m = 0; m < strArray2.Length; m++)
            {
      //数组一已经存在的直值是否包含指定的键值,不包含的才取出来
                if (!map.ContainsKey(strArray2[m]))
                {
                    strs += strArray2[m] + ",";
                }
            }

           Response.Write("strArray1字符串数组跟字符串数组strArray2比较,strArray1字符串数组中不含有strArray2数组中的有:" + strs);

posted @ 2013-07-08 16:50  猎鹰-aspnet  阅读(2792)  评论(0编辑  收藏  举报