c#搜索整数数组列表

时间:2017-05-08 17:50:15

标签: c#

我有一个int数组列表。

如何搜索特定的var listIntArray = new List<int[]>(); listIntArray.Add(new int[] { 1, 2, 3, 4, 5, 6 }); var array1 = new int[] { 1, 2, 3, 4, 5, 6 }; bool contains1 = listIntArray.Contains(array1); //--> should be true var array2 = new int[] { 4, 5, 6 }; bool contains2 = listIntArray.Contains(array2); //--> should be false

示例:

with LeadAndLagAndGap as (
   select
      tableid,
      personID,
      startDate,
      endDate,
      lag(endDate) over (partition by personID order by startDate) as previousEnd,
      lead(startDate) over (partition by personID order by startDate) as nextStart,
      coalesce(datediff(day,endDate,lead(startDate) over (partition by personID order by startDate))-1,0) as gap
   from
      #DateRanges
), OnlyStartAndEndRows as (
   select
      tableid,
      personID,
      startDate,
      endDate,
      previousEnd,
      nextStart,
      gap
   from
      LeadAndLagAndGap
   where
      previousEnd is null  -- Definitely FIRST record in a range
      or nextStart is null -- Definitely LAST record in a range
      or gap > 0           -- Definitely an end of a range, nextStart is definitely the start of a range.
), PreCollapseReaggregate as (
   select
      tableid,
      personID,
      startDate,
      endDate,
      previousEnd,
      nextStart,
      gap,
      case
         when previousEnd is null then startDate
         when gap > 0 then nextStart
      end as DefiniteStart,
      case
         when nextStart is null then endDate
         when gap > 0 then endDate
      end as DefiniteEnd
   from
      OnlyStartAndEndRows
), Collapsed as (
   select
      tableid,
      personID,
      DefiniteStart as startDate,
      case
         when definiteEnd is null or gap > 0 then lead(definiteEnd) over (partition by personid order by startdate)
         when definiteStart is not null and DefiniteEnd is not null then definiteEnd
      end as endDate
     from PreCollapseReaggregate
)
select * from Collapsed
where enddate is not null

1 个答案:

答案 0 :(得分:2)

你可以用LINQ做到这一点。

bool result = listIntArray.Any(arr => arr.SequenceEqual(array1));