Getting a string to only accept 0's and 1's
I don't understand what is wrong with this line of code in particular: bool result = userInput.All(c=>Char.IsLetter(c) && c=='1' && c=='0');
![](https://utfs.io/f/874b2999-344b-4acf-8519-18386417434f-1nq2cb.png)
29 Replies
it cant be '1' and '0' at the same time
oh i see
should i make two bool results then?
or would that work
Use an or
Not an and
char is letter and (1 or 0)
oh
i'll try that rq
now that I think about it, does this strong not work in my case?
![](https://utfs.io/f/4166c231-2428-424a-87e3-ac3c330ac06b-1nq2cb.png)
i originally had the if statement set to false, but even if I put in 0's and 1's it would still think that I put something else
is there a way to modify the bool result to only have c=='1' or c=='0'? i think the char.isLetter is the problem
i think 1 and 0 arent letters
you should remove the is lettee
would I replace the IsLetter with IsDigit in that case?
oh perfect
that was it
just is 0 or 1 is enough
lemme try that
![](https://utfs.io/f/3c8b6a05-7de6-42b3-8343-244a5de0069e-1nq2cb.png)
what do you mean by this?
something is definitely going over my head
c =>
nothin
oooooh
is that a pointer?
no you arent using pointers
wait no
so what does c => mean?
im guessing is character c 1 or 0?
All
takes a function as input. You need to give it a function. =>
is a way to define a function (called a lambda) inline...like
Func<int, bool> isChar0or1 = c => c is '0' or '1';
Func<char, bool>
šok thats too complex
and just real quick, a function is also a method right
yeah i realised
sorry
its 1 am
i cant sleep
void Foo() { ... } or Action foo = () => { ... }
ate nearly the same thing but the last one is a delegate refering to a lambda instead of an ordenary method
oh so its a difference regarding format?
ill try go sleep
for sure
thanks for the help!
it has some other differences
gotcha, def got a lot to learn
sleep well š
lambdas are useful but can be tricky
thanks