我有以下代码应该从来自服务器的字符串生成列表项。代码如下:
foreach (String str in years)
{
if (string.IsNullOrEmpty(str) || str.Equals(" "))
{
System.Diagnostics.Debug.WriteLine("empty");
}
else
{
System.Diagnostics.Debug.WriteLine(str);
yearLi.Value = str;
yearList.Add(yearLi);
count = yearList.Count;
}
System.Diagnostics.Debug.WriteLine("count-->" + count);
}
现在我的问题是,如果字符串数组“years”有 {2011,2012},则列表应该是 2011 和 2012。但它有 2012,2012。我无法在此代码中找到错误。请指教。