Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Active reading [<https://en.wiktionary.org/wiki/white_space#Noun>]. [(its = possessive, it's = "it is" or "it has". See for example <https://www.youtube.com/watch?v=8Gv0H-vPoDc&t=1m20s> and <https://www.wikihow.com/Use-Its-and-It%27s>.)]
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

There seems to be a lot of complexity here when all you need is:

 /// <summary>  /// Returns the input string with the first character converted to uppercase if a letter  /// </summary>  /// <remarks>Null input returns null</remarks>  public static string FirstLetterToUpperCase(this string s)  {   if (string.IsNullOrWhiteSpace(s))   return s;   return char.ToUpper(s[0]) + s.Substring(1);  } 

Noteworthy points:

  1. ItsIt's an extension method.

  2. If the input is null, empty or whitespacewhite space the input is returned as is.

  3. String.IsNullOrWhiteSpace was introduced with .NET Framework 4. This won't work with older frameworks.

There seems to be a lot of complexity here when all you need is:

 /// <summary>  /// Returns the input string with the first character converted to uppercase if a letter  /// </summary>  /// <remarks>Null input returns null</remarks>  public static string FirstLetterToUpperCase(this string s)  {   if (string.IsNullOrWhiteSpace(s))   return s;   return char.ToUpper(s[0]) + s.Substring(1);  } 

Noteworthy points:

  1. Its an extension method.

  2. If the input is null, empty or whitespace the input is returned as is.

  3. String.IsNullOrWhiteSpace was introduced with .NET Framework 4. This won't work with older frameworks.

There seems to be a lot of complexity here when all you need is:

/// <summary> /// Returns the input string with the first character converted to uppercase if a letter /// </summary> /// <remarks>Null input returns null</remarks> public static string FirstLetterToUpperCase(this string s) { if (string.IsNullOrWhiteSpace(s)) return s; return char.ToUpper(s[0]) + s.Substring(1); } 

Noteworthy points:

  1. It's an extension method.

  2. If the input is null, empty or white space the input is returned as is.

  3. String.IsNullOrWhiteSpace was introduced with .NET Framework 4. This won't work with older frameworks.

Source Link
Stephen Kennedy
  • 21.8k
  • 24
  • 99
  • 114

There seems to be a lot of complexity here when all you need is:

 /// <summary> /// Returns the input string with the first character converted to uppercase if a letter /// </summary> /// <remarks>Null input returns null</remarks> public static string FirstLetterToUpperCase(this string s) { if (string.IsNullOrWhiteSpace(s)) return s; return char.ToUpper(s[0]) + s.Substring(1); } 

Noteworthy points:

  1. Its an extension method.

  2. If the input is null, empty or whitespace the input is returned as is.

  3. String.IsNullOrWhiteSpace was introduced with .NET Framework 4. This won't work with older frameworks.