Cannot implicitly convert type 'string' to 'int' error

后端 未结 3 869
梦谈多话
梦谈多话 2021-01-28 05:33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

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


        
相关标签:
3条回答
  • 2021-01-28 05:39

    You are converting a to an int but your switch statement is matching it to strings. Change it to case 1: instead of case "1" to fix the issues.

    0 讨论(0)
  • 2021-01-28 05:45

    Remove quotes in case. i.e.

    Replace case "1": with case 1:

    0 讨论(0)
  • 2021-01-28 05:48

    The offending code are your case statements. a is an int. Your case statements all use strings. Simply remove the quotes around the numbers:

    switch(a)
    {
        case 1: 
                // some code
                break;
        case 2: 
                // some code
                break;
        // rest of cases
    }
    
    0 讨论(0)
提交回复
热议问题