December 2018
Beginner to intermediate
668 pages
15h 30m
English
In the StringExtensions class, add the static modifier before the class, and add the this modifier before the string type, as highlighted in the following code:
public static class StringExtensions
{
public static bool IsValidEmail(this string input)
{
These two changes inform the compiler that it should treat the method as a method that extends the string type.
Back in the Program class, add some new statements to use the extension method for strings:
WriteLine($"{email1} is a valid e-mail address:{email1.IsValidEmail()}.");
WriteLine($"{email2} is a valid e-mail address:{email2.IsValidEmail()}.");
Note the subtle change in the syntax. The IsValidEmail method now appears to be an instance ...
Read now
Unlock full access