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 odpowiedzi
+ 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