Wie entferne ich die Warnung „Mögliches Null-Referenzargument für Parameter“C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 Wie entferne ich die Warnung „Mögliches Null-Referenzargument für Parameter“

Post by Anonymous »

Kann mir bitte jemand sagen, wie ich diese Warnung im folgenden Code entfernen kann

Mögliches Nullreferenzargument für Parameter „item“ in „void List.Add(object item)“

Dies ist der Code und die Warnung wird in diesen Zeilen angezeigt

Code: Select all

rowDataList = [.. rowCollection[headRow].ItemArray];
Ich habe eine Nullprüfung hinzugefügt, aber sie scheint keine Auswirkungen zu haben.

Code: Select all

DataSet dataSet = reader.AsDataSet(conf);
DataRowCollection rowCollection;

if (checkData == 0)
rowCollection = dataSet.Tables[sheetName].Rows;
else
rowCollection = dataSet.Tables[0].Rows;

int rowCount = rowCollection.Count;

if (rowCollection != null && rowCollection.Count > headRow)
{
rowDataList = [.. rowCollection[headRow].ItemArray];
await AssertIsTrue(rowCount != 0, $"Assert there are rows in the report file, the count is {rowCollection.Count}");

if (rowNumb != 0)
await AssertIsTrue(rowCount - 1 == rowNumb, $"Assert there are rows in the report file match the page, the count is {rowCollection.Count}");

//now check the first row is correct
await TopIsGoodCheck(topRow, rowDataList);

if (checkData != 0)
await CheckForData(checkData, rowCollection);

if (dataColumns != null && rowCollection.Count > 1)
{
rowDataList = [.. rowCollection[1].ItemArray];
await DataColumnsCheck(rowDataList, dataColumns);
}
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post