While the question of checking whether the input is a string type has been closed. Two answers raised the question of micro-optimization: which of the following two solutions will work best?
string myString = "RandomStringOfLetters";
bool allLetters = myString.All( c => Char.IsLetter(c) );
string s = "RandomStringOfLetters";
bool allLetters = Regex.IsMatch(s, "^[a-z]+$", RegexOptions.IgnoreCase);
Not wanting to just ask Reed or Mark a question, I thought I would write a quick test to determine which ones are better. The problem is that I did not do much code optimization (I usually prefer to read the code above all the others).
Except that you make a timestamp before and after running each of them, what are some other (better?) Options for determining which solution works faster?
Edit
I modified Martin's answer to work with Console.WriteLine(...)and ran it as a console application. Not sure exactly how LinqPad launches applications, but the results are about the same:
41
178
source
share