Time for action – consuming our new Extension method
Now, let's see how we can consume this method:
- Stay in the project you created. Add a console application. Call it
StringExTest
. - Add a reference of
StringEx
class library to this project: - Add the following using directive in
Program.cs
:using StringEx;
- Add the following string variable in the
Main()
method. This validates Swedish zip codes:string pattern = @"^(s-|S-){0,1}[0-9]{3}\s?[0-9]{2}$";
- Add a few test input strings in a
List
of strings:List<string> testInputs = new List<string>() {"12345", "425611", "932 68", "S-621 46", "5367", "31 545" };
Iterate through all these test inputs to find out whether ...
Get .NET 4.0 Generics now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.