zoukankan      html  css  js  c++  java
  • 两数组相比筛选数据

    static void Main(string[] args)
            {
               
    int[] a = new int[] { 2, 4, 5, 7, 8 };
               
    int[] b = new int[] { 9, 4, 5, 6, 7, 8 };
               
    //不要用数组 老出错
                  ArrayList alist = new ArrayList(a);
                  ArrayList blist
    = new ArrayList(b);
                ArrayList same
    = new ArrayList();
                ArrayList aDif
    = new ArrayList();
                ArrayList bDif
    = new ArrayList();

              
    foreach(object o in alist)
               {
                  
    if (blist.Contains(o))
                   {
                       same.Add(o);
                   }
                  
    else {
                       aDif.Add(o);
                   }
               }
               
               
    foreach (object o in blist)
               {
                  
    if (!same.Contains(o))
                   {
                       bDif.Add(o);
                   }
               }


                Console.WriteLine(
    "相同的");
               
    foreach (Object o in same)
                    Console.Write(
    "   {0}", o);
                Console.WriteLine();
                Console.WriteLine(
    "a中特有的");
               
    foreach (Object o in aDif)
                    Console.Write(
    "   {0}", o);
                Console.WriteLine();
                Console.WriteLine(
    "b中特有的");
               
    foreach (Object o in bDif)
                    Console.Write(
    "   {0}", o);

                Console.Read();
            }
  • 相关阅读:
    今天没事做了个MBTI职业倾向测试
    Prototype 源码解读[资源]
    ◎◎identity ,ident_current() ,scope_identity的区别
    进军SharePoint,资料先行....
    这两天写了个分页控件,分享代码
    高效率的object转int的函数
    可填可选的DropDownList Server Control
    [DHTML]setInterval与setTimeout的区别
    提两个建议
    通过XSL template与import实现代码重用
  • 原文地址:https://www.cnblogs.com/cxy521/p/1348573.html
Copyright © 2011-2022 走看看