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

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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题