Ram Prasad

Ram Prasad

  • NA
  • 326
  • 16.7k

using array from custom class and them compare it with other

Sep 25 2019 9:03 PM
I would like to use NWCdecimal[] in Main while comparing it with decimal[] to get the output. However, I am not able to compare the two and getting error "Operator '==' cannot be applied to operands of type 'NWC' and 'int'" How this can be achieved? Also, NECdecimal[] cannot be moved out of NWC class. (This is an incomplete code, just looking to be pointed in right direction)
  1. public class NWC  
  2. {  
  3. public int Number { getset; }  
  4. public int[] NWCdecimal = new int[20]  
  5. { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};  
  6. }  
  7. public static int[] deci = new int[5]{0,1,4,5,10 };  
 
in main when I compare
  1. for (int i = 0; i < NWCdecimal.Length; i++)  
  2. {  
  3. for (int j = 0; j < deci.Length; j++)  
  4. {  
  5. if (NWCdecimal[i] == deci[j])  
  6. {  
  7. Console.WriteLine(NWCdecimal[i]);  
  8. }  
  9. else  
  10. {  
  11. Console.WriteLine(E);  
  12. }  
  13. }  
this gives me error Operator '==' cannot be applied to operands of type 'NWC' and 'int'

Answers (2)