class phone
{
public char[] pHone1 = { 'a', 'b', 'c' };
public char[][]pHone = new char[][]{new char[3]{' ',' ',' '},new char[3]{' ',' ',' '},new char[3]{ 'a','b','c'},new char[3]{'d','e','f'},new char[3]{'g','h','i'},new char[3]{'j','k','l'},new char[3]{'m','n','o'},new char[4]{'p','q','r','s'},new char[3]{'t','u','v'},new char[4]{'w','x','y','z'}};
public string show(string s)
{
string num2="";
for (int i = 0; i < s.Length; i++)
{
if (i % 2 == 0 && i != s.Length - 1)
num2 += pHone[s[i] - '0'][s[i + 1] - '0'];
if (i == s.Length - 1 && i% 2 == 0)
num2 += tostring( pHone[s[i] - '0']);
}
return num2;
}
public string tostring(char [] b)
{string num1="";
for(int i=0;i<b.Length;i++)
num1+= b[i];
return num1;
}
class morse
{
public string [] MORSE = {"-----","*----","**---","***--","****-","*****","-****","--***","---**","----*"};
public string initmorse;
public bool exam(string initmorse)
{
for (int i = 0; i < initmorse.Length; i++)
{
if (initmorse[i] == '*' || initmorse[i] == '-')
continue;
else
return true;
}
if (initmorse.Length % 5 == 0)
return !true;
else
return true;
}
public void show()
{
for( int index=0;index<=9;index++)
{
Console.WriteLine("\t{0}\t{1}", index, MORSE[index]);
}
}
public string explain(string initmorse)
{
string sum = "";
for (int i = 0; i < initmorse.Length; i++)
{
if (i % 5 != 0)
continue;
string a;
a = initmorse[i].ToString() + initmorse[i + 1] + initmorse[i + 2] + initmorse[i + 3] + initmorse[i + 4];
int index = Array.IndexOf(MORSE, a);
sum += index;
} return sum;
}
}
}
static void Main(string[] args)
{
Console.WriteLine("本程序可以实现的摩尔斯编码与解码");
Console.WriteLine("1.打印摩尔斯密码表");
Console.WriteLine("2.摩尔斯码编码");
Console.WriteLine("3.手机 按键编码");
Console.WriteLine("4.栅栏编码");
Console.WriteLine("5.退出系统");
Morse.show();
Console.WriteLine("请输入摩尔斯码:");
Morse.initmorse= Console.ReadLine();
while (Morse.exam(Morse.initmorse))
{
Console.WriteLine("存在异常字符,或者符号个数不对,请重新输入:");
Morse.initmorse = Console.ReadLine();
}
Console.WriteLine("解码数字为{0}", Morse.explain(Morse.initmorse));
// Console.WriteLine("解码数字为{0}",Morse.explain( Morse.initmorse));
phone Phone = new phone();
Phone.show(Morse.explain(Morse.initmorse));
Console.ReadLine();
}
}
}
class qwe
{
}
以上是完整代码,我想把phone类中的num2用到qwe类中,听说实例化就可以做到,然后我就在qwe类用中用 Phone.show(Morse.explain(Morse.initmorse)); ,但是报错了