sashomaga

Extension Methods

Feb 25th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. static class Program
  6. {
  7.     static void Main()
  8.     {
  9.  
  10.         string helloString = "Hello, Extension Methods!";
  11.  
  12.         int wordCount = helloString.WordCount();
  13.  
  14.         Console.WriteLine(wordCount);
  15.  
  16.     }
  17. }
  18.  
  19.  
  20. public static class StringExtensions
  21.  
  22. {
  23.  
  24.       public static int WordCount(this string str)
  25.  
  26.       {
  27.  
  28.             return str.Split(new char[] { ' ', '.', ',', '!'  },
  29.  
  30.                   StringSplitOptions.RemoveEmptyEntries).Length;
  31.  
  32.       }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment