.

extension methods / extends

using System;

namespace Bitlink.ExtensionMethods
{
    public static class StringExtensions
    {
        public static int WordCount(this String s)
        {
            return s.Split(new char[] { ' ', '.', '?' },
                             StringSplitOptions.RemoveEmptyEntries).Length;
        }


        public static string UpCaseOnlyFirstLetter(this string s)
        {
            return s.ToLower().UpCaseFirstLetter();
        }

        public static string UpCaseFirstLetter(this string s)
        {
            // Check for empty string.
            if (string.IsNullOrEmpty(s))
            {
                return string.Empty;
            }
            // Return char and concat substring.
            return char.ToUpper(s[0]) + s.Substring(1);
        }
    }
}

What's your thoughts on this?

*

Protected by WP Anti Spam