Skip to content
Loading
How to get difference between two array without using linq or Set oper
  • Amit Mohanty
    Try this
    1. public static void GetDiffValue(string[] array1, string[] array2)  
    2. {  
    3.     for (int i = 0; i < array1.Length; i++)  
    4.     {  
    5.         bool valueFound = false;  
    6.         for (int j = 0; j < array2.Length; j++)  
    7.         {  
    8.             if (array1[i] == array2[j])  
    9.                 valueFound = true;  
    10.         }  
    11.         if (!valueFound)  
    12.             Console.WriteLine(array1[i]);  
    13.     }  
    14. }  
    15.   
    16. static void Main(string[] args)  
    17. {  
    18.     var array1 = new[] { "A""B""C" };  
    19.     var array2 = new[] { "A""C""D" };  
    20.     GetDiffValue(array1, array2);  
    21.     GetDiffValue(array2, array1);  

    +1
  • thank you for reply
    this is correct result
    but this solution with linq 
    i don't need solution with linq or set
    i need it with any solution without linq or set operator 
    +1
  • Amit Mohanty
    Try this
    1. var array1 = new[] { "A""B""C" };  
    2. var array2 = new[] { "A""C""D" };  
    3.   
    4. var result = array2.Except(array1).Concat(array1.Except(array2)); 
    +1