I have a function for getting a string to have only the first letter to be uppercase.
public class Class1
{
public static string UppercaseFirst(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).ToLower();
}
}
Example:
string MyName = "john";
string result = Class1.UppercaseFirst(MyName)
Result: "John"
Is it possible to remove the “Class1.” before the call to the function?
Make it an extension method then you can call it like
"john".UppercaseFirst();You just need to declare your class as static and change the signature to the following