Advertisement
Guest User

LinqCollectionExtensions

a guest
Apr 25th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System.Collections.Generic;
  2.  
  3. namespace EvidenceCenter.NativeSQLiteParsing.Extensions
  4. {
  5.   public static class LinqCollectionExtensions
  6.   {
  7.     public static bool Any<TSource>(this TSource[] source)
  8.       => source.Length > 0;
  9.  
  10.     public static TSource Last<TSource>(this TSource[] source)
  11.       => source[source.Length - 1];
  12.  
  13.     public static TSource LastOrDefault<TSource>(this TSource[] source)
  14.     {
  15.       var length = source.Length;
  16.       return length == 0 ? default(TSource) : source[length - 1];
  17.     }
  18.  
  19.     public static TSource First<TSource>(this TSource[] source)
  20.       => source[0];
  21.  
  22.     public static TSource FirstOrDefault<TSource>(this TSource[] source)
  23.       => source.Length == 0 ? default(TSource) : source[0];
  24.  
  25.     public static int Count<TSource>(this TSource[] source)
  26.       => source.Length;
  27.  
  28.     public static bool Any<TSource>(this ICollection<TSource> source)
  29.       => source.Count > 0;
  30.  
  31.     public static TSource Last<TSource>(this IList<TSource> source)
  32.       => source[source.Count - 1];
  33.  
  34.     public static TSource LastOrDefault<TSource>(this IList<TSource> source)
  35.     {
  36.       var count = source.Count;
  37.       return count == 0 ? default(TSource) : source[count - 1];
  38.     }
  39.  
  40.     public static TSource First<TSource>(this IList<TSource> source)
  41.       => source[0];
  42.  
  43.     public static TSource FirstOrDefault<TSource>(this IList<TSource> source)
  44.       => source.Count == 0 ? default(TSource) : source[0];
  45.  
  46.     public static int Count<TSource>(this ICollection<TSource> source)
  47.       => source.Count;
  48.   }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement