double Temp_=[999,233,100,23.5,342,9854,3.5]
用C#从大到小排序。。高人指点。。
for (int i = 0; i < Temp_.Length; i++)
{
for (int j = i; j < Temp_.Length; j++)
{
if (Temp_[i] < Temp_[j])
{
double temp = Temp_[i];
Temp_[i] = Temp_[j];
Temp_[j] = temp;
}
}
}
用C#从大到小排序。。高人指点。。
for (int i = 0; i < Temp_.Length; i++)
{
for (int j = i; j < Temp_.Length; j++)
{
if (Temp_[i] < Temp_[j])
{
double temp = Temp_[i];
Temp_[i] = Temp_[j];
Temp_[j] = temp;
}
}
}
解决方案 »
- access数据库查询问题
- 做一个winform窗体向一个网站发送数据,网站再存储接收到的数据,怎么做,求大神解决。。
- AJAX疑问
- 浏览服务器文件夹的图片,如果图片大的,按比例修改大小后安原来文件名覆盖之前的那张图片
- 实现程序(asp.net c#)备份数据库,备份形式要求和 vs 2008 发布数据库那样既包括数据库框架和数据库数据的 .sql 脚本文件
- js 取input的值问题(.net页面)
- 网站部署问题
- 求javascript的一个小问题?
- 莱鸟问题,请各位朋友指点,关于asp数据库的问题
- 洋葱WEB富文本测试版 共享下载!
- 头一次遇到这个问题
- 球ASP.NET注册页面,别人要,急!急!急!急!
{
for (int j = i; j < Temp_.Length-i-1; j++)
{
if (Temp_[j+1] < Temp_[j])
{
double temp = Temp_[j];
Temp_[i] = Temp_[j+1];
Temp_[j+1] = temp;
}
}
}
double[] Temp_ = new double[] { 999, 233, 100, 23.5, 342, 9854, 3.5 };
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double[] Temp = { 999, 233, 100, 23.5, 342, 9854, 3.5 };
for (int i = 0; i < Temp.Length; i++)
{
for (int j = i; j < Temp.Length; j++)
{
if (Temp[i] < Temp[j])
{
double temp = Temp[i];
Temp[i] = Temp[j];
Temp[j] = temp;
}
}
Console.Write(Temp[i]+" ");
}
}
}
}
//降序排
Array.Sort<double>(Temp_, (d1, d2) => d2.CompareTo(d1));
有什么不对吗?
{
double temp = Temp_[j-1];
Temp_[j-1] = Temp_[j];
Temp_[j] = temp;
void Main()
{
//linq
double[] Temp_=new double[]{999,233,100,23.5,342,9854,3.5};
Console.WriteLine("排序前:****************");
Temp_.ToList().ForEach(t=>Console.WriteLine(t));
Console.WriteLine("排序后:****************");
Temp_=Temp_.OrderByDescending(t=>t).ToArray();
Temp_.ToList().ForEach(t=>Console.WriteLine(t));
/*
排序前:****************
999
233
100
23.5
342
9854
3.5
排序后:****************
9854
999
342
233
100
23.5
3.5*/
}
double[] TempArr = { 999, 233, 100, 23.5, 342, 9854, 3.5 };
for (int i = 0; i < TempArr.Length; i++)
{
for (int j = i; j < TempArr.Length; j++)
{
if (TempArr[i] < TempArr[j])
{
double tempItem = TempArr[i];
TempArr[i] = TempArr[j];
TempArr[j] = tempItem ;
}
}
Console.Write(TempArr[i]+" ");
}这是冒泡,数组自带的排序也不错,效率最高,冒泡是基础!最简单,实现容易效率很低.
for(int i=0;i<temp_.length;i++)
{
if(temp_[i]!="")//为什么这里不起作用高人指点
str=temp[i].split('|')[0];//未将对象引用设置到对象的实例
}
list.Sort(delegate(double a,double b) {...
from q in arr orderby q select q
{
if(temp_[i]!="")//怎么不起作用?
string str=temp[i].split('|')[0];}//此处必须声明变量str
static void Main(string[] args)
{
string[] temp={"999|aa","","","88|bb","77|ee"};
for(int i=0;i<temp.Length;i++)
{
if (temp[i] != "")
{
string str = temp[i].Split('|')[0];
Console.Write(str+" ");
}
}
}