使用switch case语句的问题

Har*_*mar -9 .net c# console console-application

我的代码如下.基本上,我正在读取一个excel文件并将其内容存储到一个对象数组中.然后,我使用switch case语句来执行不同的操作.检查下面的代码: -

  using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.ComponentModel;
using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Excel;
namespace Excel1
{
    class Program
    {
        public static void Main(string[] args)
        //public void ExcelOps()
        {
            //string str;
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"D:/WebServiceTemplate.xlsx");
            Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
            Excel.Range xlRange = xlWorksheet.UsedRange;
            int rowCount = xlRange.Rows.Count;
            int colCount = xlRange.Columns.Count;
            int numSheets = xlWorkbook.Sheets.Count;
            //
            // Iterate through the sheets. They are indexed starting at 1.
            //
            for (int sheetNum = 1; sheetNum <=1; sheetNum++)
            {
                Worksheet sheet = (Worksheet)xlWorkbook.Sheets[sheetNum];
                //
                // Take the used range of the sheet. Finally, get an object array of all
                // of the cells in the sheet (their values). 
                //
                object[,] valueArray = (object[,])xlRange.get_Value(XlRangeValueDataType.xlRangeValueDefault);

                //
                // Do something with the data in the array with a custom method.
                //                
                ProcessInput(valueArray);
            }
        }
        public static void ProcessInput(object[,] valueArray)
        {
            foreach (var value in valueArray)
            {
                switch ((string)value.ToString())
                {
                    case "ITemplate.GetAllTemplate":
                        {
                            //ITemplate.GetAllTemplate
                            break;
                        }
                    case "ITask.GetTaskInstanceFromTemplate":
                        {
                            //ITask.GetTaskInstanceFromTemplate
                            break;
                        }
                    case "CreateTask":
                        {
                            //CreateTask
                            break;
                        }
                    case "UpdateDatabase":
                        {
                            //UpdateDatabase
                            break;
                        }
                    case "GetTaskStatus":
                        {
                            //GetTaskStatus
                            break;
                        }
                    case "VerifyValue":
                        {
                            //VerifyValue
                        }
                        break;
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当我构建它时,我得到一个错误 对象引用未设置为对象的实例.
错误出现在switch语句中

有人可以帮我弄这个吗?

O. *_*per 6

错误消息是指您之后括号中变量的类型switch.在你的情况下,这是一个数组,所以显然不是(如错误信息所示)bool,char,string,integral,enum或相应的可空类型.