Saturday, August 9, 2014

C# Extension Method - Sample

class Program
{
    static void Main(string[] args)
    {
        string s = "hello please tell me the word count";
        Console.Write(s.WordCount());
        Console.Read();
    }
}

public static class StringExtension
{
    public static int WordCount(this string value)
    {
        return value.Split(' ').Length;
    }
}

No comments: