当前位置:编程学习 > C#/ASP.NET >>

怎么排除1-10这10个数中其中4个数?

现有数组a中有1到10 10个数,要排除b数组中4个10以内的数 得出的数放在richtextbox1中显示  如何用C#写?求高手留下神圣的脚印。 --------------------编程问答-------------------- 你直接遍历不行么?
for(int i =0;i<shuzuB.Length;i++)
{
    for(int j = 0;j<shuzuA.Length;j++)
    {
        if(shuzuB[i]!=shuzuA[j])
        {
             richtextbox1.AppendText(shuzuA[j].ToString());
}
}
}
代码现写的,不知道拼写对不对,反正就这么个意思。 --------------------编程问答-------------------- int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray(); --------------------编程问答-------------------- int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8, 9, 2, 5, 11,23,55,77,89, 11,2 };
从b中选四个小于10的排除

--------------------编程问答-------------------- 如果都是固定的10以内,可以用表驱动

    public class ArrayCheck
    {
        private int[] a = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        private int[] b = {0, 2, 0, 0, 5, 0, 7, 0, 0, 10};

        public string GetResult()
        {
            string result = string.Empty;
            for (int i = 0; i < a.Length; i++)
            {
                if(b[i]!=0) continue;
                result += a[i].ToString();
            }
            return result;
        }
    }
--------------------编程问答--------------------
引用 2 楼  的回复:
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray();


我擦 第一次见到还有这东西?Array.Except(*) 是什么特性? --------------------编程问答--------------------
引用 5 楼  的回复:
引用 2 楼  的回复:
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray();


我擦 第一次见到还有这东西?Array.Except(*) 是什么特性?


linq 扩展 --------------------编程问答-------------------- linq --------------------编程问答--------------------
引用 2 楼  的回复:
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray();

有大神在的地方总能学到犀利的东西 --------------------编程问答--------------------
引用 2 楼  的回复:
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray();

啊呀被抢滩登陆了......这个还经常用到很实用的~ --------------------编程问答--------------------
引用 5 楼  的回复:
引用 2 楼  的回复:
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int[] b = { 2, 4, 6, 8 };
int[] result = a.Except(b).ToArray();


我擦 第一次见到还有这东西?Array.Except(*) 是什么特性?

a集合中排出b集合的内容 --------------------编程问答-------------------- 果然是大神呀
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,