This program contains a static class of extension methods. The IsUpper and IsLower methods are public static methods written with the extension method syntax.
using System;
static class Extensions
{
public static bool IsUpper(this string value)
{
// Consider string to be uppercase if it has no lowercase letters.
for (int i = 0; i < value.Length; i++)
{
if (char.IsLower(value[i]))
{
return false;
}
}
return true;
}
public static bool IsLower(this string value)
{
// Consider string to be lowercase if it has no uppercase letters.
for (int i = 0; i < value.Length; i++)
{
if (char.IsUpper(value[i]))
{
return false;
}
}
return true;
}
}
class Program
{
static void Main()
{
Console.WriteLine(
"test".IsLower());
// True
Console.WriteLine(
"test".IsUpper());
Console.WriteLine(
"Test".IsLower());
Console.WriteLine(
"Test".IsUpper());
Console.WriteLine(
"TEST3".IsLower());
Console.WriteLine(
"TEST3".IsUpper());
// True
}
}
True
False
False
False
False
True