Search code examples
c#numbersintegerint

How to check if an integer includes a certain number in c#


Is there a way I can check Integers if they contain a certain number in C#?

For example:

I want to check for 7. When I enter 17, the code will return 1. When I enter 28, the code will return 0.

Thank You


Solution

  • int number = 17;
    int digit = 7;
    bool result = number.ToString().Contains(digit.ToString());