Suppression State Error CS0021 Cannot apply indexing with [] to an expression of type 'object' | Selenium C# Forum
S
Swathi Posted on 09/07/2019

Hi,

 

Can you please help me resolve this error?

using DataReader;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExcelReaderFile
{
    class DummyTest
    {
        [Test]
        public void TestA()
        {

        }

        public object[] getData()
        {
            string fileName = ConfigurationManager.AppSettings["TestDataSheetPath"];

            string TestCaseName = "TC3";
        
            string sheetName = "Sheet1";

            ExcelReader excel = new ExcelReader(fileName);
            int testStartRow = excel.getRowNumber(sheetName, 0, TestCaseName);
            int dataStartRow = testStartRow + 2;
            int colStartRow = testStartRow + 1;
            int row = 0;
            while (!excel.getCellData(sheetName, 0, dataStartRow + row).Equals(""))
            {
                row++;
            }

            int col = 0;
            while (!excel.getCellData(sheetName, col, colStartRow).Equals(""))
            {
                col++;
            }


            //Read the data
            object[] data = new object[row][];
            int dataRow = 0;
            for (int i = dataStartRow; i < dataStartRow + row; i++)
            {
                data[i - dataStartRow] = new object[col];
                for (int j = 0; j < col; j++)
                {
                   data[dataRow][j] = excel.getCellData(sheetName, j, i);
                }
                dataRow++;
            }
            
           // Console.ReadKey();
        }
    
    }
}

 



G
gunjan Replied on 16/07/2019

Can you please share the code.


S
Swathi Replied on 17/07/2019

Hi Gunjan,

 

I have already added my code.

 

Please let me know if you can not access

 

Thanks,

Swathi


S
Swathi Replied on 20/07/2019

Please close this as I have resolved the issue


G
gunjan Replied on 24/07/2019

What was the issue?


S
Swathi Replied on 26/08/2019

In "Read the Data" section, i had to use "object[][] data = new object[row][];" instead of "object[] data = new object[row][];"