Bir üniversite projesinin bir parçası olarak kendi dilim için bir derleyici oluşturmaya çalışıyorum ve bir dizede (alfa, sayısal, sınırlayıcı vb.) Giriş türünü belirlemek için bir modül yazarken bu soruna rastladım. . Belirli semboller için ip nasıl test edilir? (C#)
private static void readChar(ref string sentence, ref int inputType)
{
foreach (char test in sentence)
{
if ((test.CompareTo("|") == 0) |
(test.CompareTo("*") == 0) |
(test.CompareTo("/") == 0) |
(test.CompareTo("+") == 0) |
(test.CompareTo("-") == 0) |
(test.CompareTo("@") == 0) |
(test.CompareTo("#") == 0) |
(test.CompareTo("$") == 0) |
(test.CompareTo("%") == 0) |
(test.CompareTo("^") == 0) |
(test.CompareTo("&") == 0) |
(test.CompareTo("(") == 0) |
(test.CompareTo(")") == 0) |
(test.CompareTo(",") == 0) |
(test.CompareTo("`") == 0) |
(test.CompareTo("=") == 0))
{
inputType = 5; // delimiter
}
else
{
if ((test.CompareTo("0") == 0) |
(test.CompareTo("1") == 0) |
(test.CompareTo("2") == 0) |
(test.CompareTo("3") == 0) |
(test.CompareTo("4") == 0) |
(test.CompareTo("5") == 0) |
(test.CompareTo("6") == 0) |
(test.CompareTo("7") == 0) |
(test.CompareTo("8") == 0) |
(test.CompareTo("9") == 0))
{
inputType = 3; // numeric
} // end if compareTo Numeric
else
{
if ((test.CompareTo(" ") == 0)) inputType = 6; //space
else
if ((test.CompareTo(";") == 0)) inputType = 7; //semicolon
else
{
inputType = 1; // alpha
} // end alpha
} // end else
} // end if
}
} // end readChar
bu hata verir deyimi eğer ilk ulaşır
: türü 'System.ArgumentException' işlenmeyen bir özel durum mscorlib.dlloluştu Ek bilgi: Nesne tipi Char olmalıdır.
Sınama için kullandığımı ve hatanın hangi nesneye başvurduğunu bilmediğim için bunu nasıl çözeceğimi bilmiyorum.
Okuduğunuz için teşekkürler, yardıma ^^
;' ve 'çift kullanabilirsiniz || ', tek bir' | ' anlamı yok. – Camo
"string" string parametresi neden? Ve bir döngüde 'int int 'parametresini çok kez güncellemek için ne kullanır? Bu int değişkeni kadar hızlı okumaya çalışan bir şey var mı? Ses görünmüyor. –
Tek bir düşünce, "her" giriş türü için "(...)" anahtarını değiştirip (daha sonra "her bir blokta 'case' etiketiyle) bir anahtar bloğuna sahip olmaktır. vb. –