271
1
using System;
2
using System.Diagnostics;
3
using System.Runtime.CompilerServices;
4
5
public static class Program
6
{
7
//Fri 30-Oct-20 2:17pm metadataconsulting.ca
8
//https://metadataconsulting.blogspot.com/2020/10/C-NET-Validate-Drive-Letter-with-compiler-optimization-aggressive-in-lining-for-large-fall-through-case-statements.html
9
//-> this method does not exist on the interwebs, trivial?
10
//-> fun with compiler switches to optimize case statements
11
12
public static bool isValidDriveLetter(this string drivewithcolon)
13
{
14
15
if (drivewithcolon.Length == 2 && drivewithcolon[1] == ':')
16
{
17
drivewithcolon = drivewithcolon.ToUpper();
18
// this is surprisingly faster than the equivalent if statement
19
switch (drivewithcolon[0])
20
{
21
case 'A':
22
case 'B':
23
case 'C':
24
case 'D':
Cached Result