How do I Capitalize First Letter of String in C#

 Example 1 : 
  1. public static string ToTitleCase(string str)  
  2.    {  
  3.        string result = str;  
  4.        if (!string.IsNullOrEmpty(str))  
  5.        {  
  6.            var words = str.Split(' ');  
  7.            for (int index = 0; index < words.Length; index++)  
  8.            {  
  9.                var s = words[index];  
  10.                if (s.Length > 0)  
  11.                {  
  12.                    words[index] = s[0].ToString().ToUpper() + s.Substring(1);  
  13.                }  
  14.            }  
  15.            result = string.Join(" ", words);  
  16.        }  
  17.        return result;  
  18.    }  
Input :  String strR = ToTitleCase("c sharp corner");
 
output:  C Sharp Corner
 
Example 2 :  
  1. public static string FirstCharToUpper(string input)  
  2.    {  
  3.        if (String.IsNullOrEmpty(input))  
  4.            throw new ArgumentException("Error  !");  
  5.        return CultureInfo.CurrentCulture.TextInfo.ToTitleCase(input.ToLower());  
  6.    }  
  
Input : String strR = FirstCharToUpper("c sharp corner");
output: C Sharp Corner