Here's some LINQ:
string myString = "MyStringText";
string myString2 = "My String Text";
int A = Convert.ToInt('A');
int Z = Convert.ToInt('Z');
bool isAtoZ = false;
var count = (from ch in myString.ToUpper()
where (int)ch >= A && (int)ch <= Z
select ch).Count();
isAtoZ = (count == myString.Length);
var count2 = (from ch in myString2.ToUpper()
where (int)ch >= A && (int)ch <= Z
select ch).Count();
isAtoZ = (count2 == myString.Length);
Using Regex (sample already provided)
Using just the string:
string myString = "MyStringText";
bool isAtoZ = true;
foreach(char ch in myString.ToUpper())
{
if ((int)ch < Convert.ToInt('A') || (int)ch > Convert.ToInt('Z'))
{
isAtoZ = false;
break;
}
}
Using helper objects with LINQ:
string validChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string myString = "MYStringText";
bool isAtoZ = true;
var count = (from ch in myString.ToUpper()
where validChars.Contains(ch)
select ch).Count();
isAtoZ = (count == myString.Length);
As you can see, there are a million ways to do the same thing, and if you had been paying attention in class, you would realize that your instructor gave you all the knowlege and reference material to accomplish your homework assignment. Even if you claim it's NOT a homework assignment, considering you had to ask for help with such a simple task should be an indication that maybe computer programming ain't exactly your calling in life, and maybe society would be better off if you were to become a wet paint monitor.