文件名称:.net 字符串排序
文件大小:961B
文件格式:CS
更新时间:2015-11-02 04:17:27
排序 冒泡
用冒泡根据字符串长度排序排序
string[] names = new string[4];
names[0] = "adsaa";
names[1] = "司asdas法所";
names[2] = "sadasaasd";
names[3] = "qwwd";
string tmp = "";
for (int i = 0; i < names.Length; i++)
{
for (int j = i; j < names.Length; j++)
{
if (names[i].Length < names[j].Length)
{
tmp = names[i];
names[i] = names[j];
names[j] = tmp;
}
}
}
for (int i = 0; i < names.Length; i++)
{
Response.Write(names[i] + "
");
}