Find XOR of all elements in an Array | C # program to find the XOR of all elements in the array ; Function to find the XOR of all elements in the array ; Resultant variable ; Iterating through every element in the array ; Find XOR with the result ; Return the XOR ; Driver Code ; Function call
using System ; class GFG { static int xorOfArray ( int [ ] arr , int n ) { int xor_arr = 0 ; for ( int i = 0 ; i < n ; i ++ ) { xor_arr = xor_arr ^ arr [ i ] ; } return xor_arr ; } public static void Main ( string [ ] args ) { int [ ] arr = { 3 , 9 , 12 , 13 , 15 } ; int n = arr . Length ; Console . WriteLine ( xorOfArray ( arr , n ) ) ; } }