I have a 5 character long string from Console.Readline()
and I want to test if all 5 characters are different.
Asked
Active
Viewed 119 times
-1

Ashley Medway
- 7,151
- 7
- 49
- 71

bergdavi
- 13
- 2
1 Answers
6
You can use Distinct
method which will give you the distinct characters then just compare the count with the input length
, if they are equal that means all chars are different.
string input = Console.ReadLine();
bool isDifferent = input.Distinct().Count() == input.Length;
Note you need using System.Linq;
to use Distinct
method.

Selman Genç
- 100,147
- 13
- 119
- 184