[英]C# switch case problems
如何使用此代码赢得 C# 控制台应用程序。 我是编写应用程序的新手。 我需要创建将字母转换为摩尔斯电码的应用程序。
在 class 中,我们使用 Visual Studio 2015。我们在 C# 控制台应用程序中为 windows 创建应用程序。
我们的应用程序模板以:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
}
}
}
我在https://www.geeksforgeeks.org/morse-code-implementation/上找到的程序是:
// C# program to demonstrate Morse code
using System;
class GFG
{
// function to encode a alphabet as
// Morse code
static string morseEncode(char x)
{
// refer to the Morse table
// image attached in the article
switch (x)
{
case 'a':
return ".-";
case 'b':
return "-...";
case 'c':
return "-.-.";
case 'd':
return "-..";
case 'e':
return ".";
case 'f':
return "..-.";
case 'g':
return "--.";
case 'h':
return "....";
case 'i':
return "..";
case 'j':
return ".---";
case 'k':
return "-.-";
case 'l':
return ".-..";
case 'm':
return "--";
case 'n':
return "-.";
case 'o':
return "---";
case 'p':
return ".--.";
case 'q':
return "--.-";
case 'r':
return ".-.";
case 's':
return "...";
case 't':
return "-";
case 'u':
return "..-";
case 'v':
return "...-";
case 'w':
return ".--";
case 'x':
return "-..-";
case 'y':
return "-.--";
// for space
case 'z':
return "--..";
}
return "";
}
static void morseCode(string s)
{
// character by character print
// Morse code
for (int i = 0;i<s.Length; i++)
Console.Write(morseEncode(s[i]));
Console.WriteLine();
}
// Driver code
public static void Main ()
{
string s = "geeksforgeeks";
morseCode(s);
}
}
// This code is contributed by vt_m.
我的问题是:如何实现此代码以使用我的模板。 我需要创建应用程序 tahat 正在使用 switch case 将字母转换为莫尔斯。
感谢,并有一个愉快的一天。
请检查以下。
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
GFG.morseEncode('a');
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.