0

ÂżCreen que se puede hacer escribir mĂĄs corto el programa?

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string password = Console.ReadLine(); char[] notAllowedSymbols = { '!', '#', '

#x27;, '%', '&', '(', ')', '*', ',', '+', '-' }; //tu cĂłdigo va aquĂ­ for(int i=0;i<11;i++){ if(password.Contains(notAllowedSymbols[i])){ Console.WriteLine("Invalid"); break;} } } } }

19th Dec 2020, 11:05 PM
Andy Eliu GonzĂĄlez PĂ©rez
Andy Eliu GonzĂĄlez PĂ©rez - avatar
3 Answers
+ 2
You could use foreach like this: foreach(var symbol in notAllowedSymbols) or Any like this: if notAllowedSymbols.Any(s => password.Contains(s))
19th Dec 2020, 11:46 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
0
I guess you have to output something for a valid password as well
19th Dec 2020, 11:09 PM
Benjamin JĂŒrgens
Benjamin JĂŒrgens - avatar
0
In fact it is all that they ask me in the task, I only had the doubt if the shorter code can be written
19th Dec 2020, 11:13 PM
Andy Eliu GonzĂĄlez PĂ©rez
Andy Eliu GonzĂĄlez PĂ©rez - avatar