public static class ExtensionMethod
{
public static string UppercaseFirstLetter(this string value)
{
// Uppercase the first letter in the string.
if (value.Length > 0)
{
char[] array = value.ToCharArray();
array[0] = char.ToUpper(array[0]);
return new string(array);
}
return value;
}
}
//"THIS" in the signature of a method means method can be called in the class preceding the keyword this
class Program
{
static void Main(string[] args)
{
string value = "dot net perls";
value = value.UppercaseFirstLetter();
Console.WriteLine(value);
Console.ReadLine();
}
}