+ 1

[Solved] Is there an easier way to test for numbers in Password Validation than explicitly typing each number to test for?

https://code.sololearn.com/cyFFgWA0f5bu/?ref=app

6th Feb 2021, 6:13 PM
Elijah Brown
Elijah Brown - avatar
6 Answers
+ 2
You could use Enumerable.Range() char[] availableNumbers = Enumerable.Range(48, 57).Select(i => (char)i).ToArray();
6th Feb 2021, 6:45 PM
♡Addy♡
♡Addy♡ - avatar
+ 2
It's taking the integer values from our Range and casting them to their corresponding Ascii character E.g 48 => '0' , 49 => '1' , 50 => '2' and so on
6th Feb 2021, 7:06 PM
♡Addy♡
♡Addy♡ - avatar
+ 1
Yes. 'i' is our integer value from the range, and (char)i is changing(type casting) our data type from integer to char. Sorry if it's hard to understand, my technical talk in English isn't the best
6th Feb 2021, 7:32 PM
♡Addy♡
♡Addy♡ - avatar
0
So I understand that Enumerable.Range(0, 9) would make a range from 0-9, but what does the '.Select(i => (char)i)' do?
6th Feb 2021, 6:53 PM
Elijah Brown
Elijah Brown - avatar
0
So 'i' represents the value eg: 45? Or does 'i' represent the index? And why is char in parentheses next to the 'i'?
6th Feb 2021, 7:16 PM
Elijah Brown
Elijah Brown - avatar
0
Thank you, that answers my question. ♡Addy♡
6th Feb 2021, 7:35 PM
Elijah Brown
Elijah Brown - avatar