解决方案 »

  1.   

    过滤规则:
    1.前后2条记录相差小于100 即 (A-B)绝对值< 100 例如:A:30  B:150  C:40 那么忽略掉B
    2.后一条数据必须比前一条数据大 例如:A:30  B:20  C:40 则忽略B 现提供如下数组做测试:
    double[] array = new Double[] 
    {
    21.1,
    23.3,
    24.4,
    25.5,
    26.6,
    20.1,
    26.8,
    27.2,
    27.4,
    0,
    28,
    29,
    30,
    150,
    31 
    };所需过滤掉的数据:20.1、0、150 
      

  2.   

    不是linq的List<double> newArray = array.Distinct().ToList();
    double first = newArray[0];
    for (int i = 1; i < newArray.Count;)
    {
         if (newArray[i] > first && newArray[i] - first < 100)
              first = newArray[i++];
         else 
              newArray.Remove(newArray[i]); 
    }
      

  3.   


    嗯 很对 是这个意思。只是如果用 Linq 怎么写?
      

  4.   

    逆序遍历,再按照你的规则判断,Remove就可以
      

  5.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                double[] array = new Double[] 
                {
                21.1,
                23.3,
                24.4,
                25.5,
                26.6,
                20.1,
                26.8,
                27.2,
                27.4,
                0,
                28,
                29,
                30,
                150,
                31 
                };
                var query = array.Select((x, i) => new { x, i }).Zip(array.Skip(1), (f, s) => new { f = f.x, s, i = f.i + 1 }).Where(x => x.f > x.s || x.f < x.s - 100);
                foreach (var item in query)
                {
                    Console.WriteLine("index {0} value {1}", item.i, item.s);
                }
            }
        }
    }index 5 value 20.1
    index 9 value 0
    index 13 value 150
    index 14 value 31
    Press any key to continue . . .
      

  6.   

    List<double> result=new List<double>(){array.First()};

    array.Aggregate((x,y)=>
    {
    if(y>x && y-x<100) {result.Add(y); return y;}
    else return x;
    });
      

  7.   

    以上方法都很对 但是前提条件是 第1条数据必须是准确的 假如我换成 如下数据:
    double[] array = new Double[] 
    {
    24
    23.3,
    24.4,
    25.5,
    26.6,
    20.1,
    26.8,
    27.2,
    27.4,
    0,
    28,
    29,
    30,
    150,
    31 
    };
    那么 以上方法貌似都不行了,其实 总结规则就是:排除异常增大的点。
      

  8.   

    static void Main(string[] args)
            {
                var array = new Double[] { 21.1, 23.3, 24.4, 25.5, 26.6, 20.1, 26.8, 27.2, 27.4, 0, 28, 29, 30, 150, 31 }.ToList();
                List<double> result = new List<double>();
                int index;
                var first = GetFirst(array, out index);
                if (first == -1)
                {
                    Console.WriteLine("给定集合中没有复合条件的元素");
                    return;
                }            if (index > 0)
                {
                    array.RemoveRange(0, index - 1);
                }            result.Add(first);
                var temp = (from item in array
                            select Check(item, result)).ToList();
                Console.WriteLine(string.Join(", ", result));
            }        /// <summary>
            /// 根据给定规则检查
            /// </summary>
            /// <param name="para"></param>
            /// <param name="result"></param>
            /// <returns></returns>
            static double Check(double para, List<double> result)
            {
                var last = result[result.Count - 1];
                if (para > last && (para - last < 100)) result.Add(para);
                return para;
            }        /// <summary>
            /// 寻找第一个满足条件的数
            /// </summary>
            /// <param name="source"></param>
            /// <param name="index"></param>
            /// <returns></returns>
            static double GetFirst(List<double> source, out int index)
            {
                var count = source.Count();
                index = 0;
                for (int i = 0; i < count; i++)
                {
                    if (++index > count)  return -1;
                    if (source[i] < source[index] && (source[index] - source[i] < 100))
                    {
                        index = i;
                        break;
                    }                if (index == count) return -1;
                }            return source[index];
            }下面的for循环都可以转换为linq查询,时间关系,这里就不在赘述了。这里我觉得楼主是需要一个在linq里调用方法的方法吧