qq_43412960 2018-11-11 03:18 采纳率: 78.6%
浏览 814
已结题

C#实现从一个类中调用一个值

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));        ,但是报错了
  • 写回答

2条回答 默认 最新

  • threenewbee 2018-11-11 05:39
    关注

    Morse在哪里定义的?
    应该加上
    morse Morse = new morse();
    Morse.show();


    你的程序写得很乱,你不如把题目给我,我一次性给你写一个,你照着参考下。

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器