Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue using switch case statement
    primarykey
    data
    text
    <p>My code is as follows. Basically, I am reading an excel file and storing its contents into an object array. Then, I use a switch case statement to do different operations. Check my code below:-</p> <pre><code> 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 &lt;=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; } } } } } </code></pre> <p>When I build it, I get an error <strong>Object reference not set to an instance of an object.</strong><br> the error appears in the switch statement</p> <p>Can someone help me with this? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload