csharp basic exercises: Get Planet Name By ID [Difficulty: 0] - view the C # programming classic exam, exercises of varying difficulty C #, C # novice suitable for self-study of advanced training

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_45444821/article/details/102715224

csharp basic exercises: Get Planet Name By ID [Difficulty: 0]:

This function returns an incorrect value. Can you figure out why?

getPlanetName(3); //应该返回"地球"

get_planet_name(3)# 应该返回 '地球'

get_planet_name(3)# 应该返回 '地球'

getPlanetName(3)# 应该返回 '地球'

Programming objectives:

public class Kata
{
  public static string GetPlanetName(int id)
  {
    string name;
    switch(id)
    {
      case 1:
        name = "Mercury";
      case 2:
        name = "Venus";
      case 3:
        name = "Earth";
      case 4:
        name = "Mars";
        name = "Jupiter";
      case 6:
        name = "Saturn";
      case 7:
        name = "Uranus";
      case 8:
        name = "Neptune";


Test sample:

namespace Solution {
  using NUnit.Framework;
  using System;
  [TestFixture]
  public class SolutionTest
  {
    [Test]
    public void Test()
      Assert.AreEqual("Jupiter", Kata.GetPlanetName(5));
    }
  }
}


Best answer (multiple solutions):

Click to view answer

More related topics:

csharp basic exercises: There are no vowels in there [Difficulty: 0] -? View more classic C # programming exam, exercises of varying difficulty C #, C # novice suitable for self-study of advanced training

Disclaimer

This blog All programming topics and answers were collected from the Internet, users are mainly used for study and reference, if any violation of your rights, please contact the administrator to delete, thank
entitled to collect https://www.codewars.com/
HTTPS: / /www.codewars.com/kata/get-planet-name-by-id

Guess you like

Origin blog.csdn.net/weixin_45444821/article/details/102715224