daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int[] array1 = {1 ,2 ,3 ,-5 ,2 ,0 };
  2. int[] array2 = {1 ,2 ,3 ,-1 ,5 ,0 };
  3. int[] array3 = {1 ,2 ,3 ,-6 ,2 ,9 };
  4.    
  5. Console.WriteLine(array1.Union(array2.Union(array3)).Where((x) => x >=0).Count)
  6.    
  7. Console.WriteLine(array1.Union(array2).Union(array3).Count(x => x >= 0));
  8.    
  9. Console.WriteLine(string.Join(",", array1.Union(array2).Union(array3).Where(x => x >= 0)));
  10. //Prints: 1, 2, 3, 0, 5, 9
  11.    
  12. array1.Union(array2).Union(array3)
  13.    
  14. var concatenated = new int[array1.Length + array2.Length + array3.Length];
  15. array1.CopyTo(concatenated, 0);
  16. array2.CopyTo(concatenated, array1.Length);
  17. array3.CopyTo(concatenated, array1.Length + array2.Length);
  18.    
  19. var arr1 = new[] {1, 2, 3, -5, 2, 0};
  20.         var arr2 = new[] {1, 2, 3, -1, 5, 0};
  21.         var arr3 = new[] {1, 2, 3, -6, 2, 9};
  22.         var result = arr1
  23.             .Concat(arr2)
  24.             .Concat(arr3)
  25.             .Distinct()
  26.             .Where(i => i >= 0)
  27.             .ToArray();
  28.    
  29. //
  30.     //
  31.     ///<summary>Create a new array as concatenation of all given arrays.</summary>
  32.     public static T[] Concatenate<T>( params T[][] args ) {
  33.         if ( null == args ) return null;
  34.         // Get argument lengths
  35.         var count = args.Length;
  36.         if ( 0 == count ) return null;
  37.         var lengths = new int[ count ];
  38.         // Compute all and total lengths
  39.         var total = 0;
  40.         for ( int i = 0; i < count; i++ ) {
  41.             lengths[ i ] = null == args[ i ] ? 0 : args[ i ].Length;
  42.             total += lengths[ i ];
  43.         }
  44.         if ( 1 > total ) return null;
  45.         // Create target array
  46.         T[] a = new T[ total ];
  47.         // Copy all together
  48.         total = 0;
  49.         for ( int i = 0; i < count; i++ ) {
  50.             if ( null != args[ i ] ) {
  51.                 args[ i ].CopyTo( a, total );
  52.             }
  53.             total += lengths[ i ];
  54.         }
  55.         return a;
  56.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top