Try changing your code to use
As Array
and use
var
for your declarations. E.g. (I've also added in some null checking)
if (si.MeaningCount > 0)
{
var strMeanings = si.MeaningList as Array;
if (strMeanings != null)
foreach (var strMeaning in strMeanings)
{
var objMeaning = strMeaning;
var aSynonyms = si.SynonymList[objMeaning];
var strSynonyms = si.SynonymList[objMeaning] as Array;
if (strSynonyms != null)
foreach (string strSynonym in strSynonyms)
{
lbSynonym.Items.Add(strSynonym);
}
}
}
else
{
lbSynonym.Items.Add("NONE");
}
This article for reference:
How to: Safely Cast by Using as and is Operators (C# Programming Guide)[
^]