+ 1
What's wrong with this code ?
Edit : Why does this code loop the true. https://code.sololearn.com/cf6WrHQR8L01/?ref=app
5 Answers
+ 3
Main is void function, you write return statement in main for what purpose.. It's an error..
If you mean for output, write like this..
if (char.IsNumber(e) || convert[e] <= 1 || convert[e] >= 0)
{
Console.WriteLine(true);
}
else
{
Console.WriteLine(false);
}
+ 1
It worked jayakrishna, thanks. But the foreach loop loops the true output with number of characters. How do I solve that ?.
+ 1
What you are trying..? What is your required output..?
Edit:
Also
convert [e] is not works.. Because there e is charecter either '0' or '1'. convert[e] means convert[48] or convert[49], indexoutofbounds exception..
Write just e=='1' , e=='0'
+ 1
Jayakrishna, thanks again.
0
Its true because char.isNumber(e) is always true..
For a single true or false.. Like this:
static void Main(string[] args)
{
string input = "101101";
char[] convert = input.ToCharArray();
bool b=true;
foreach (var e in convert)
{
if(char.IsNumber(e) && (e == '1' || e == '0'))
{
continue;
}
else
{
b=false;
break;
}
}
Console.WriteLine(b);
}
And Joseph Oritseweyinmi
you're welcome ...