Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum Multiple Tests Returning Error Message
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading.Tasks; // aljodav // http://rextester.com/users/376 namespace Rextester { using P=Rextester.Program; public class Program { public static bool Test1(string s){ return s.Length>=5; } public static bool Test2(string s){ return s.Contains(' '); } public static bool Test3(string s){ return !s.StartsWith(" "); } public static bool Test4(string s){ return !s.EndsWith(" "); } /* ----------------------------------------------------------- */ public static string Test(Predicate<string> p,string s,string m){ if(p(s))return"";else return m; } /* ------------------------------------------------------------ */ public static void Main(string[] args) { Predicate<string>[] predicates={ P.Test1, P.Test2, P.Test3, P.Test4, }; string[] errorMsgs={ "① The string cannot have less than 5 characters.", "② The string must contain one space character at least.", "③ The string cannot start with a space character.", "④ The string cannot end with a space character.", }; string testString=" 1y "; List<string> list= new List<string>(); Array.ForEach(predicates,p=>list.Add(Test(p,testString,errorMsgs[list.Count]))); Console.WriteLine("Error msgs ( or blank if no error ):\n"); list.ForEach(s=>Console.WriteLine("{0,5} {1}",s==string.Empty,s)); Console.WriteLine("\nAll tests succeeded: {0}", list.TrueForAll(s=>s==string.Empty)); } } }
run
|
edit
|
history
|
help
0
STAN
Plt-D v.0.9.3.1
cte-like constructs in C#
Floyd’s Warshall Algorithm
Square Integer Matrix
a
a6
Something
A2Z Dice Roll
Hack