Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- static class Program
- {
- static void Main()
- {
- string helloString = "Hello, Extension Methods!";
- int wordCount = helloString.WordCount();
- Console.WriteLine(wordCount);
- }
- }
- public static class StringExtensions
- {
- public static int WordCount(this string str)
- {
- return str.Split(new char[] { ' ', '.', ',', '!' },
- StringSplitOptions.RemoveEmptyEntries).Length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment