向各位请教个问题:我有这样一组数字,
第一组:(A,x1,y1,z1,)
第二组:(B,x2,y2,z2,)
第二组:(C,x3,y3,z3,)



对数组的后三个数字进行对应比较(x进行比较,y进行比较,z进行比较),如果完全相同(例如:x1=x2,y1=y2,z1=z2),则显示A和B。
请问各位:这个怎么实现啊?!多谢各位!

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;namespace WebApplication1
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {        }        protected bool ArrayComparison(Item Item1, Item Item2)
            {
                if (Item1.x1 == Item2.x1 && Item1.y1 == Item2.y1 && Item1.z1 == Item2.z1)
                { return true; }
                return false;
            }    }    public class Item
        {
            public int x1;        public int y1;        public int z1;
        }
    }
      

  2.   

    int[] a = new int[4]{A,x1,y1,z1};
    int[] b = new int[4]{B,x2,y2,z2};
    int[] c = new int[4]{C,x3,y3,z3};public string Compare(int[] item1, int[] item2)
    {
        if(item1[1] == item2[1] && item1[2] == item2[2] && item1[3] == item2[3])
           {
                 return item1[0].ToString() + "|" + item2[0].ToString() ;
           }
        else
           {
                 return "";
           }
    }
      

  3.   

    定义一个2维数组string[][] str = new string[][] { new string[] { "A", "x1", "y1", "z1" }, new string[] { "B", "x1", "y2", "z1" }, new string[] { "C", "x1", "y2", "z1" } };//你把值改为变量
                for (int i = 0; i < str.Length-1; i++)
                {
                    foreach (string[] s in str)
                    {
                        if (str[i][1] == str[i + 1][1])
                        {
                            return str[i][0] + "&" + str[i+1][0];
                        }
                    }
                }
      

  4.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;namespace TestCSDN
    {
        class MyArr 
        {
            private String c;
            private int x;
            private int y;
            private int z;        public MyArr(String s, int x, int y, int z)
            {
                c = s;
                this.x = x;
                this.y = y;
                this.z = z;
            }        public static bool Compared(MyArr a,MyArr b )
            {
                if (a.x == b.x && a.y == b.y && a.z == b.z)
                    return true;
                else
                    return false;
            }    }
        class Program
        {
                    static void Main(string[] args)
            {
                MyArr a = new MyArr("A",1,1,1);
                MyArr b = new MyArr("B", 1, 1, 1);
                MyArr c = new MyArr("C", 1, 2, 3);            Console.WriteLine(MyArr.Compared(a,b));
                Console.WriteLine(MyArr.Compared(a, c));        }
        }
    }
      

  5.   

    int[] a = new int[4]{A,x1,y1,z1};
    int[] b = new int[4]{B,x2,y2,z2};
    int[] c = new int[4]{C,x3,y3,z3};if(a[1]==b[1] && a[1]==b[1] && a[1]==b[1])
    {
       console.write(a[0] +" and  " +b[0]);}
    else
     {
        console.writeline("the array A and B no compare");
    }