> if (i >= 65 && i <= 90 || i >= 96 && i <= 122 || i == 39)
> {
> e.Handled = false;
> return;
> }
If one is going to do it that way, IMHO it is better to not convert to
integers. Even if you just did "if (e.KeyChar >= 'A' && e.KeyChar <= 'Z'
|| e.KeyChar >= 'a' && e.KeyChar <= 'z' || e.KeyChar == '\'' || e.KeyChar
== '-')", that would be more readable and more maintainable. Even better
is that you can do "if (Char.IsLetter(e.KeyChar) || e.KeyChar == '\'' ||
e.KeyChar == '-')", which is even more readable and maintainable.
(ignoring for the moment that your code leaves out one of the possible
characters...the fact that I have to go to an ASCII table to figure out
whether you forgot the apostrophe or the hyphen is an example of the lack
of readability of your code :) ).
Pete
Tim Sprout - 31 May 2007 06:01 GMT
> if (i >= 65 && i <= 90 || i >= 96 && i <= 122 || i == 39)
> {
> e.Handled = false;
> return;
> }
If one is going to do it that way, IMHO it is better to not convert to
integers. Even if you just did "if (e.KeyChar >= 'A' && e.KeyChar <= 'Z'
|| e.KeyChar >= 'a' && e.KeyChar <= 'z' || e.KeyChar == '\'' || e.KeyChar
== '-')", that would be more readable and more maintainable. Even better
is that you can do "if (Char.IsLetter(e.KeyChar) || e.KeyChar == '\'' ||
e.KeyChar == '-')", which is even more readable and maintainable.
(ignoring for the moment that your code leaves out one of the possible
characters...the fact that I have to go to an ASCII table to figure out
whether you forgot the apostrophe or the hyphen is an example of the lack
of readability of your code :) ).
Pete
Thanks for the comments, Pete!
-Tim Sprout