你如何把这个过程放在课堂上? [英] How do you put the process in a class ?
问题描述
你如何把这个过程放在课堂上?
char a
;
a
= char.Parse(textBox1.Text);
//如果输入是元音则运行此
if(a =='a'|| a =='A'|| a =='e'|| a =='E'|| a =='i'|| a =='我'||
a ==' o'|| a =='O'|| a =='u'|| a =='U')
{
//输出>
textBox2.Text =Vowel;
textBox1.Clear();
}
//如果输入则运行此项是一个辅音
if( a
=='b'|| a
== 'B'||
a
=='c'|| a
== 'C'|| a
=='d'|| a
== 'D'|| a
=='f'|| a =='F'||
a
=='g'|| a
=='G'|| a
=='h'|| a
=='H'|| a
=='j'|| a =='J'||
a
=='k'|| a
=='K'|| a
=='l'|| a
=='L'|| a
=='m'|| a =='M'||
a
=='n'|| a
=='N'|| a
=='p'|| a
=='P'|| a
=='q'|| a =='Q'||
a
=='r'|| a
=='R'|| a
=='s'|| a =='S'|| a
=='t'|| a =='T'||
a
=='v'|| a
=='V'|| a
=='w'|| a
=='W'|| a
=='x'|| a
=='X'||
a
=='y'|| a
=='Y'|| a
=='z'|| a
=='Z')
{
//输出
textBox2.Text =辅音;
textBox1.Clear();
}
我尝试过:
没有什么比这更重要的
how do you put the process in a class ?
char a
;
a
= char.Parse(textBox1.Text);
// run this if input is a vowel
if (a == 'a' || a == 'A' || a == 'e' || a == 'E' || a == 'i' || a == 'I' ||
a == 'o' || a == 'O' || a == 'u' || a == 'U')
{
//output
textBox2.Text = "Vowel";
textBox1.Clear();
}
//run this if input is a consonant
if ( a
== 'b' || a
== 'B' ||
a
== 'c' || a
== 'C' || a
== 'd' ||a
== 'D' || a
== 'f' || a == 'F' ||
a
== 'g' || a
== 'G' || a
== 'h' || a
== 'H' || a
== 'j' || a == 'J' ||
a
== 'k' || a
== 'K' || a
== 'l' ||a
== 'L' || a
== 'm' || a == 'M' ||
a
== 'n' || a
== 'N' || a
== 'p' || a
== 'P' || a
== 'q' || a == 'Q' ||
a
== 'r' || a
== 'R' || a
== 's' || a == 'S' || a
== 't' || a == 'T' ||
a
== 'v' || a
== 'V' || a
== 'w' || a
== 'W' || a
== 'x' || a
== 'X' ||
a
== 'y' || a
== 'Y' || a
== 'z' ||a
== 'Z')
{
//output
textBox2.Text = "Consonant";
textBox1.Clear();
}
What I have tried:
nothing so farrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
推荐答案
坦率地说,那段代码非常讨厌。
而不是那样,创建两个数组:
Frankly, that code is very nasty.
Instead of that, create two arrays:
private static char[] vowels = "aeiou".ToArray();
private static char[] consonants = "bcdfghjklmnpqrstvwxyz".ToArray();
现在,忘记char.Parse存在,并执行此操作:
Now, forget that char.Parse exists, and do this:
if (textBox1.Text.Length >= 1)
{
char ch = textBox1.Text[0];
ch = char.ToLower(ch);
if (vowels.Contains(ch))
{
// ...
}
else if (consonants.Contains(ch))
{
// ...
}
else
{
// ...
}
}
看看有多可读那是什么?
没有你需要做的就是阅读关于课程和方法的笔记,你应该在那里。
See how much more readable that is?
No all you need to do is read your notes on classes and methods, and you should be there.
这篇关于你如何把这个过程放在课堂上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!