Answer the question
In order to leave comments, you need to log in
How to use a variable of type char?
How to remove a char variable from an array for viewing in a loop?
string password = Console.ReadLine();
char[] notAllowedSymbols = { '!', '#', '$', '%', '&', '(', ')', '*', ',', '+', '-' };
for (int i = 0; i < notAllowedSymbols; i++)
{
if (i.Contains(notAllowedSymbols))
break;
Console.WriteLine("Invalid");
}
Answer the question
In order to leave comments, you need to log in
Let's try to figure it out.
An array is a limited set of some data of a particular type.
char[] notAllowedSymbols = { '!', '#', '$', '%', '&', '(', ')', '*', ',', '+', '-' };
array[index]
var firstChar = notAllowedSymbols[0]; // '!'
private static bool IsValid(string password)
{
char[] notAllowedSymbols = { '!', '#', '$', '%', '&', '(', ')', '*', ',', '+', '-' };
for (int i = 0; i < notAllowedSymbols.Length; i++)
{
if (password.Contains(notAllowedSymbols[i]))
{
return false;
}
}
return true;
}
1. i is an integer (int) and notAllowedSymbols is an array. In the condition of the for loop, you are comparing a number with an array. You can not do it this way. You need to compare the number with the length of the array.
2. In the if condition, you check that i (which is an integer) contains an array of characters. How can a number contain symbols? Apparently you need to check whether the password string contains a character from the notAllowedSymbols array with index i.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question