using System.Diagnostics;
using System.Runtime.CompilerServices;
public static class Program
public static bool isValidDriveLetter(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
switch (drivewithcolon[0])
public static bool isValidDriveLetterV2(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
if (drivewithcolon[0] >= 'A' && drivewithcolon[0] <= 'Z')
[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
public static bool isValidDriveLetterV3(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
switch (drivewithcolon[0])
[MethodImplAttribute(MethodImplOptions.AggressiveOptimization)]
public static bool isValidDriveLetterV4(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
switch (drivewithcolon[0])
[MethodImplAttribute(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool isValidDriveLetterV5(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
switch (drivewithcolon[0])
[MethodImplAttribute(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
public static bool isValidDriveLetterV6(this string drivewithcolon)
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
drivewithcolon = drivewithcolon.ToUpper();
if (drivewithcolon[0] >= 'A' && drivewithcolon[0] <= 'Z')
public static void Main()
bool v1,v2,v3,v4,v5,v6 = false;
Stopwatch sw = new Stopwatch();
v1= "Z:".isValidDriveLetter();
Console.WriteLine("is Z: valid drive letter ?{0}, v1 in {1} ticks.",v1.ToString(), sw.ElapsedTicks);
v2= "Z:".isValidDriveLetterV2();
Console.WriteLine("is Z: valid drive letter ?{0}, v2 in {1} ticks.",v2.ToString(), sw.ElapsedTicks);
v3= "Z:".isValidDriveLetterV3();
Console.WriteLine("is Z: valid drive letter ?{0}, v3 in {1} ticks.",v3.ToString(), sw.ElapsedTicks);
v4= "Z:".isValidDriveLetterV4();
Console.WriteLine("is Z: valid drive letter ?{0}, v4 in {1} ticks.",v4.ToString(), sw.ElapsedTicks);
v5= "Z:".isValidDriveLetterV5();
Console.WriteLine("is Z: valid drive letter ?{0}, v5 in {1} ticks.",v5.ToString(), sw.ElapsedTicks);
v6= "Z:".isValidDriveLetterV6();
Console.WriteLine("is Z: valid drive letter ?{0}, v6 in {1} ticks.",v6.ToString(), sw.ElapsedTicks);