简体   繁体   中英

C# switch case problems

How can I use this code win C# Console application. I am total greenhorn in writeing apps. I need to create app that converts alphabet to morse code.

In class we use visual studio 2015. We are crating app in C# console applications for windows.

Our apps templates starts with:

   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)
        {
        }
    }
    }

Program I found on https://www.geeksforgeeks.org/morse-code-implementation/ Is:

 // 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. 

My question is: How can I implement this code to work with my tamplate. I need to create app tahat is useing switch case for convert alphabet to morse.

Thanks and have a nice day.

Please check below.

namespace ConsoleApplication4
{
   class Program
   {
      static void Main(string[] args)
      {

        GFG.morseEncode('a');

      }
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM