C#查找数组中相同的项并合并
2012-10-25 20:39
453 查看
CSDN 问题帖:查找数组中相同的项并合并.C#这个真心没SQL方便.哈哈.可能不懂LINQ吧.求指导.
http://topic.csdn.net/u/20121024/20/e395374b-176e-4f4e-899e-e360e6aa72df.html?87994
按SQL中的办法.传一个ID.写个函数合并值.用C#实现如下
http://topic.csdn.net/u/20121024/20/e395374b-176e-4f4e-899e-e360e6aa72df.html?87994
按SQL中的办法.传一个ID.写个函数合并值.用C#实现如下
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SumString { class Program { static string[,] str = new string[,] { { "1", "aaa" }, { "1", "bbb" }, { "2", "ccc" }, { "2", "ddd" }, { "3", "uuu" }, { "1", "eee" }, { "4", "aaa" }, { "4", "qqq" } }; static List<string[,]> list = new List<string[,]>(); static List<string> listid = new List<string>(); static void Main(string[] args) { Addlist(); foreach (string[,] str in list) { if (!listid.Contains(str[0, 0])) { if(SumString(str).TrimEnd(new char[]{','}).Contains(",")) Console.WriteLine("{0}--{1}", str[0, 0], SumString(str).TrimEnd(new char[]{','})); } listid.Add(str[0,0]); } Console.ReadKey(); } public static string SumString(string [,] para) { string str=""; foreach (string[,] s in list) { if (s[0, 0] == para[0,0]) { str += s[0, 1] + ","; } } return str; } public static void Addlist( ) { string[,] tempstr = new string[1, 2]; for (int i = 0; i < str.GetLength(0); i++) { tempstr = new string[1, 2]; for (int j = 0; j < str.GetLength(1); j++) { if(j==0) tempstr[0, 0] = str[i, j]; else tempstr[0, 1] = str[i, j]; } list.Add(tempstr); } } } }
相关文章推荐
- c#面试题 查找整型数组中重复出现次数最多的数字,次数相同数字按从小到大排序
- PHP数组函数一网打尽(合并,拆分,追加,查找,删除等)
- 查找数组里相同元素的个数
- js数组工具处理之合并相同字段分组
- 用XML结点的属性值查找相同结点的其它属性值[C#]
- 两个有n个数的整数数组,都排好序了。 用O(n)的时间查找两个数组是否有相同的数字。
- 两个有序数组长度分别为m,n,最多m+n次查找找出相同的数
- 查找一个字符串数组中两个或两个以上的相同字符串(swfit,oc)
- js中比较两个数组中是否含有相同的元素,可去重,可删除合并为新数组
- C# 拆分 合并 数组
- C# 合并两个int数组 合并后根据大小排序 并输出
- 累加两个php数组,键相同的累加,不同的合并
- C#对多个集合和数组的操作(合并,去重,判断)
- php 数组根据某一个键值,键值相同,则合并数组
- 查找算法之查找一个数组中两两数字相同,只有其中两个数字是不一样的,将其找出
- php 操作数组 (合并,拆分,追加,查找,删除等)
- 查找一个排好序的数组中绝对值不相同的数的个数
- c#合并两个数组方法
- 两数组合并 相同键合并不同键填0
- php 操作数组 (合并,拆分,追加,查找,删除等)