111,126
社区成员
发帖
与我相关
我的任务
分享string st = "1,4,2,";
st = st.Remove(st.Length - 1, 1); // 可以改为:st = st.Trim(',');
string[] k = st.Split('|'); // 应该是 st.Split(',')using System;
class Program
{
static void Main()
{
string st = "1,4,2";
st = Sort(st);
Console.WriteLine(st); // 输出:4,2,1
}
static string Sort(string s)
{
string[] t = s.Split(',');
Array.Sort(t);
Array.Reverse(t); // 反序
return string.Join(",", t);
}
}using System;
class Program
{
static void Main()
{
string st = "1,4,2";
st = Sort(st);
Console.WriteLine(st); // 输出:1,2,4
}
static string Sort(string s)
{
string[] t = s.Split(',');
Array.Sort(t);
return string.Join(",", t);
}
}using System;
using System.Collections;
public class ReverserCompare : IComparer
{
int IComparer.Compare(object x, object y)
{
return new CaseInsensitiveComparer().Compare(y, x);
}
}
class Program
{
static void Main()
{
ArrayList a = new ArrayList();
a.Add(1);
a.Add(4);
a.Add(2);
a.Sort(new ReverserCompare()); // 这时a的内容是:4 2 1
foreach (int x in a)
{
Console.WriteLine(x);
}
}
}
/* 程序输出:
4
2
1
*/using System;
using System.Collections;
class Program
{
static void Main()
{
ArrayList a = new ArrayList();
a.Add(1);
a.Add(4);
a.Add(2);
a.Sort(); // 这时a的内容是:1 2 4
a.Reverse(); // 这时a的内容是:4 2 1
foreach (int x in a)
{
Console.WriteLine(x);
}
}
}
/* 程序输出:
4
2
1
*/using System;
using System.Collections;
class Program
{
static void Main()
{
ArrayList a = new ArrayList();
a.Add(1);
a.Add(4);
a.Add(2);
a.Sort();
foreach (int x in a)
{
Console.WriteLine(x);
}
}
}
/* 程序输出:
1
2
4
*/ArrayList() a = new ArrayList();
a.Add(1);
a.Add(4);
a.Add(2);
a.Sort();