Given two unsorted arrays , find all pairs whose sum is x | C # Code for Given two unsorted arrays , find all pairs whose sum is x ; Function to find all pairs in both arrays whose sum is equal to given value x ; Insert all elements of first array in a hash ; Subtract sum from second array elements one by one and check it 's present in array first  or not ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static void findPairs ( int [ ] arr1 , int [ ] arr2 , int n , int m , int x ) { Dictionary < int , int > s = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { s [ arr1 [ i ] ] = 0 ; } for ( int j = 0 ; j < m ; j ++ ) { if ( s . ContainsKey ( x - arr2 [ j ] ) ) { Console . WriteLine ( x - arr2 [ j ] + " ▁ " + arr2 [ j ] ) ; } } } public static void Main ( string [ ] args ) { int [ ] arr1 = new int [ ] { 1 , 0 , - 4 , 7 , 6 , 4 } ; int [ ] arr2 = new int [ ] { 0 , 2 , 4 , - 3 , 2 , 1 } ; int x = 8 ; findPairs ( arr1 , arr2 , arr1 . Length , arr2 . Length , x ) ; } }