遍历list,做如下操作即可
1. 第二个和第一个对比如果是上升这记录上升,并将结果保存到一个临时变量
2.第三个和第二个对比如果对比结果和临时变量不一致则记录当前结果,吧结果保存到临时变量,如果对比结果一致则不做处理。
解决方案 »
- 晕了,撞鬼了。。。C#2012 DataGridView 出怪事? 不能做全选付值。。。。。
- webBrowser1的问题求高人
- 自定义控件,窗体的异常处理
- C# 怎么在sql数据库中插入一行数据
- 痛哭!连不上ORACLE数据库!都快一个月了,哪位帮忙解决下!
- 数据库的菜鸟问题
- XP启动时有个蓝屏,怎么取消掉?
- 一个win forms多窗体应用程序是否要每一个窗体都包含一个Sqlconnect?急!!!!
- 对Rectangle旋转了下,但是它的坐标仍然是之前的坐标,怎么获得旋转后的坐标?
- 请问有人用过.net里的安装程序做过c#的安装吗?能不能给点提示或例子?
- 怎么把TextBox(多行模式)的内容直接赋值给 List<string>?
- 一个DataTable引用另一个Table会占用双倍资源吗
for int i=0 i<list.count i++
{
var x=list[i];
cw(i==0?"起":(x>list[i-1]?"上升":"下降"));
}
List<int> list = new List<int>();
list.Add(15);
list.Add(12);
list.Add(16);
list.Add(14);
list.Add(13);
list.Add(10);
list.Add(18);
for (int i = 0; i < list.Count; i++)
{
var x = list[i];
Response.Write(i == 0 ? "起<br>" : (x > list[i - 1] ? "上升" : "下降")+"<br>");
}
得到
起
下降
上升
下降
下降
下降
上升
应该和你胃口吧..
List<double> list = new List<double> { 39.5, 41.5, 43.5, 50, 48, 48.5, 49, 49.5, 48.5, 47.5, 46.5 };
int trend = 0;
for (int i = 1; i < list.Count; i++)
{
if (trend == 0)
{
if (list[i] > list[i - 1])
{
trend = 1;
Console.WriteLine("上升");
}
else
{
trend = -1;
Console.WriteLine("下降");
}
}
else if (trend == 1 && list[i] < list[i - 1])
{
Console.WriteLine("下降");
trend = -1;
}
else if (trend == -1 && list[i] > list[i - 1])
{
Console.WriteLine("上升");
trend = 1;
}
}
List<int> list = new List<int>();
list.Add(15);
list.Add(12);
list.Add(16);
list.Add(14);
list.Add(13);
list.Add(10);
list.Add(18); List <string> result=new List<string> ();
for(int i=0;i<list.Count;i++)
{
if (i == 0)
result.Add("Start");
else if (list[i] > list[i - 1] && result.Last() != "Up")
result.Add("Up");
else if (list[i] < list[i - 1] && result.Last() != "Down")
result.Add("Down");
}