怎么样取数组的中不重复的元素呢? 怎么样取数组的中不重复的元素呢?一个string数组,我要取4次,如何取才能取出不重复的元素呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 一点技术含量都没有...str.GroupBy(c => c).Select(s => s.Key).OrderBy(k => Guid.NewGuid()).Take(4).ToList().ForEach((c) =>{ Console.WriteLine(c); }); private string NewMethod( string [] s) { // string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++) { bool f = false; L.Clear(); L.Add(s[j]); for (int i = j + 1; i < s.Length; i++) { if (!L.Contains(s[i])) { L.Add(s[i]); if (L.Count == 4) { f = true; break; } } } if (f) { break; } } string sr =null; if (L.Count != 4) return null; foreach (string ss in L) sr = sr + ss; return sr; } private string [] NewMethod( string [] s) { // string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++) { bool f = false; L.Clear(); L.Add(s[j]); for (int i = j + 1; i < s.Length; i++) { if (!L.Contains(s[i])) { L.Add(s[i]); if (L.Count == 4) { f = true; break; } } } if (f) { break; } } string sr = ""; if (L.Count != 4) return null; foreach (string ss in L) sr = sr + ss+","; return sr.Trim(',').Split(','); } private string [] NewMethod( string [] s,int n)//取n个 { // string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++) { bool f = false; L.Clear(); L.Add(s[j]); for (int i = j + 1; i < s.Length; i++) { if (!L.Contains(s[i])) { L.Add(s[i]); if (L.Count == n) { f = true; break; } } } if (f) { break; } } string sr = ""; if (L.Count != n) return null; foreach (string ss in L) sr = sr + ss+","; return sr.Trim(',').Split(','); } C#效果 用C#怎么实现打印功能??像Word那样, 什么是“Windows Forms”??不就是System.window.forms.form所代表的窗口吗?? 我要做一個在線軟件安裝,請教該怎么做?在線等!!! DataTable的主键问题 C#里用OracleClient类访问Oracle数据库的问题 如何在statusbar上添加ProgressBar? C#,怎么做一个简单版的EXCEL 关于类型转换问题,回家再来看结果……拜托 WinForm 中 DataGrid 的一个简单问题 (在线等待) WPF中一个非常奇怪的问题 C#中文本框换行
str.GroupBy(c => c).Select(s => s.Key).OrderBy(k => Guid.NewGuid()).Take(4).ToList().ForEach((c) =>{ Console.WriteLine(c); });
private string NewMethod( string [] s)
{
// string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++)
{
bool f = false;
L.Clear();
L.Add(s[j]);
for (int i = j + 1; i < s.Length; i++)
{
if (!L.Contains(s[i]))
{
L.Add(s[i]);
if (L.Count == 4)
{
f = true;
break;
}
} }
if (f)
{
break;
}
}
string sr =null;
if (L.Count != 4)
return null;
foreach (string ss in L)
sr = sr + ss;
return sr;
}
private string [] NewMethod( string [] s)
{
// string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++)
{
bool f = false;
L.Clear();
L.Add(s[j]);
for (int i = j + 1; i < s.Length; i++)
{
if (!L.Contains(s[i]))
{
L.Add(s[i]);
if (L.Count == 4)
{
f = true;
break;
}
} }
if (f)
{
break;
}
}
string sr = "";
if (L.Count != 4)
return null;
foreach (string ss in L)
sr = sr + ss+",";
return sr.Trim(',').Split(',');
}
private string [] NewMethod( string [] s,int n)//取n个
{
// string[] s = new string[] { "5", "2", "5", "8", "8", "1", "1" }; List<string> L = new List<string>(); for (int j = 0; j < s.Length; j++)
{
bool f = false;
L.Clear();
L.Add(s[j]);
for (int i = j + 1; i < s.Length; i++)
{
if (!L.Contains(s[i]))
{
L.Add(s[i]);
if (L.Count == n)
{
f = true;
break;
}
} }
if (f)
{
break;
}
}
string sr = "";
if (L.Count != n)
return null;
foreach (string ss in L)
sr = sr + ss+",";
return sr.Trim(',').Split(',');
}