I'm new to c#. I'm trying to send a list item as a parameter of a function. Before the moment it is passed the item exists. But inside the function it appears to be null. I would be grateful if anyone could explain me my mistake.
List<HSCodeData> HSCodeDataList;
internal void buildHSCodeDocument(List<HSCodeData> initHSCodeDataList)
{
HSCodeDataList = initHSCodeDataList;
foreach (HSCodeData dataItem in HSCodeDataList)
{
if ((dataItem != null)&&(dataItem.HSCode!=""))
{
string descriptionString = BuildDescriptionString(dataItem);
dataItem.ParentHSCode = descriptionString;
}
}
}
internal string BuildDescriptionString(HSCodeData HSCodeDataItem)
{
string descriptionString = HSCodeDataItem.Description + ItemSuggestedDescription(HSCodeDataItem);
if ((ItemHasParent(HSCodeDataItem.ParentHSCode)) && (HSCodeDataList != null) && (HSCodeDataList.Count != 0))
{
descriptionString += BuildDescriptionString(findParentItem(HSCodeDataItem.ParentHSCode));
}
return descriptionString;
}
In buildHSCodeDocument
there is no way the argument passed to BuildDescriptionString
could be null
. But there is a recursive call to BuildDescriptionString
where the return value of findParentItem
is passed. Probably findParentItem
returns null
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments