检查重复数 本帖最后由 yangxic 于 2009-07-17 18:41:23 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 int[] a = new int[] { 3, 1, 2, 1, 3, 3, 4, 5, 6, 5 }; ArrayList _ArrayList = new ArrayList(); for (int i = 0; i < a.Length; i++) { int b = a[i]; int c = 0; for (int j = 0; j < a.Length; j++) { if (b == a[j]) c++; if (c == 2) { _ArrayList.Add(a[i]); break; } } } string _str = string.Empty; for (int i = 0; i < _ArrayList.Count; i++) { _str += _ArrayList[i].ToString(); } MessageBox.Show(_str); 数据量大可以使用ado.net,把数据先导入数据表里面,在通过DataTable的DefaultView的ToTable方法具体可以参考这个帖子:http://topic.csdn.net/u/20090629/09/87284117-494a-47c2-97a8-322821c16cc3.html try... static void Main(string[] args) { Int32[] array=new Int32[]{3,1,2,1,3,3,4,5,6,5}; Dictionary<Int32, Int32> dic = new Dictionary<int,int>(); for (int i = 0; i < array.Length; i++) { if (!dic.ContainsKey(array[i])) dic.Add(array[i], 1); else dic[array[i]]++; } for (int i = 0; i < array.Length; i++) { if(dic[array[i]]>1) Console.WriteLine(array[i]); } } 下面输出代码已通过验证 输出结果为 321456private void button1_Click(object sender, EventArgs e) { int[] a = new int[] { 3, 1, 2, 1, 3, 3, 4, 5, 6, 5 }; List<int> Lt = new List<int>(); ArrayList mArrayList = new ArrayList(); bool tag = true; //设置是否存在相同值的标志,存在则为false for (int i = 0; i < a.Length; i++) { if (Lt.Count > 0) { foreach (int b in Lt) { if (b == a[i]) { tag = false; } } if (tag) { mArrayList.Add(a[i]); } if (Lt.Count != mArrayList.Count) { Lt.Add(Convert.ToInt32(mArrayList[mArrayList.Count - 1].ToString())); } tag = true; //执行一次完后重新置为true以便再次进行判断 } else { Lt.Add(a[i]); mArrayList.Add(a[i]); } } //显示 string str = string.Empty; for (int i = 0; i < Lt.Count; i++) { str += Lt[i].ToString(); } MessageBox.Show(str); } WINFORM如何实现用户发布数据的实时显示,给个思路?谢谢! 从数据库读取两个datetime日期后,怎样按间隔月份平分? 求DATAGRIDVIEW列标题宽度解决方法 小女子请求写一个服务,要求要返回图片,标题 添加对程序集的引用? 账单ID的格式 (新手问题)进来看看,怎么转换,在线等!! 服务器的连接数怎么这么少啊! 如何在winform中使用urlencode的功能[C#达人请进] 如何局部替换字符? ( 50分) 谁有好的多线程例子呀,麻烦各位网友提供几个比较好的多线程学习源码 请教IE中可以执行的JS代码,为什么在webBrowser却没有任何响应
ArrayList _ArrayList = new ArrayList();
for (int i = 0; i < a.Length; i++)
{
int b = a[i];
int c = 0;
for (int j = 0; j < a.Length; j++)
{
if (b == a[j])
c++;
if (c == 2)
{
_ArrayList.Add(a[i]);
break;
}
}
} string _str = string.Empty;
for (int i = 0; i < _ArrayList.Count; i++)
{
_str += _ArrayList[i].ToString();
} MessageBox.Show(_str);
http://topic.csdn.net/u/20090629/09/87284117-494a-47c2-97a8-322821c16cc3.html
static void Main(string[] args)
{
Int32[] array=new Int32[]{3,1,2,1,3,3,4,5,6,5};
Dictionary<Int32, Int32> dic = new Dictionary<int,int>();
for (int i = 0; i < array.Length; i++)
{
if (!dic.ContainsKey(array[i]))
dic.Add(array[i], 1);
else
dic[array[i]]++;
}
for (int i = 0; i < array.Length; i++)
{
if(dic[array[i]]>1)
Console.WriteLine(array[i]);
} }
private void button1_Click(object sender, EventArgs e)
{
int[] a = new int[] { 3, 1, 2, 1, 3, 3, 4, 5, 6, 5 };
List<int> Lt = new List<int>();
ArrayList mArrayList = new ArrayList();
bool tag = true; //设置是否存在相同值的标志,存在则为false for (int i = 0; i < a.Length; i++)
{ if (Lt.Count > 0)
{
foreach (int b in Lt)
{
if (b == a[i])
{
tag = false;
}
} if (tag)
{
mArrayList.Add(a[i]);
}
if (Lt.Count != mArrayList.Count)
{
Lt.Add(Convert.ToInt32(mArrayList[mArrayList.Count - 1].ToString()));
}
tag = true; //执行一次完后重新置为true以便再次进行判断 }
else
{
Lt.Add(a[i]);
mArrayList.Add(a[i]);
}
} //显示
string str = string.Empty;
for (int i = 0; i < Lt.Count; i++)
{
str += Lt[i].ToString();
} MessageBox.Show(str);
}