-3

Could someone help me why do i get true only if the numbers are the same? I need to find out if the second input is in the first one. True/false

int[] firstNumber;
firstNumber = new int[10];
firstNumber[0] = 
Convert.ToInt32(Console.ReadLine());
int secondNumber = 
Convert.ToInt32(Console.ReadLine()) ;

Console.WriteLine(firstNumber.Contains(secondNumber));

Edit. I need to get true for ex.:firstNumber 5214 and secondNumber 4

Rabatur
  • 3
  • 3
  • what problem are you having? How is your code not meeting your expectations? – Michael Welch Jun 22 '22 at 15:49
  • 1
    `firstNumber` is an array. – Daniel A. White Jun 22 '22 at 15:49
  • Why an array does contain a number only if that number is the one that was put there? – GSerg Jun 22 '22 at 15:50
  • "Could someone help me why do i get true only if the numbers are the same? I need to find out if the second input is in the first one." You only get true when they are the same because that's the only time the second number is in the array. – Michael Welch Jun 22 '22 at 15:51
  • hmm. and some lead how can i get true for 5432(firstNum) and 3(secondNum) – Rabatur Jun 22 '22 at 15:56
  • instead of int[] use string – Suraj Mathe Jun 22 '22 at 16:04
  • Using string instead of int will work, but I wonder if teacher expects to see some math manipulation here. Like trying to isolate every digit with math. – Dialecticus Jun 22 '22 at 16:06
  • That's a question for your teacher, and we don't know what tools (like Linq) you can use to do that, but if you knew that a string was an array of characters, how would you `Parse` each character into an `int` and put them in the array? (See [here](https://stackoverflow.com/a/4808655/1081897) for one option) – D Stanley Jun 22 '22 at 16:09

1 Answers1

0

how can i get true for 5432(firstNum) and 3(secondNum)

Use strings instead of integers, which will use string.Contains instead of Array.Contains:

string firstNumber = Console.ReadLine();
string secondNumber = Console.ReadLine();

Console.WriteLine(firstNumber.Contains(secondNumber));
D Stanley
  • 149,601
  • 11
  • 178
  • 240