30 개가 넘는 항목이있는 목록에서 모든 데이터를 반환하려고합니다. 웬일인지 나의 코드는 나에게 목록의 마지막 항목만을 준다. 나는 이것이 간단한 수정이라고 확신하지만 누구든지 나를 도울 수 있다면 그것은 위대 할 것이다. 여기에 코드가 있습니다.목록의 마지막 항목 만 가져 오기
List<string> propnumList = new List<string>();
foreach (DataRow drRow in ds7.Tables[0].Rows)
{
for (int i = 0; i < ds7.Tables[0].Columns.Count; i++)
{
propnumList.Add(drRow[i].ToString());
}
}
using (StreamWriter sw = new StreamWriter("propnumList.txt"))
{
foreach (string s in propnumList)
{
sw.WriteLine(s);
}
}
string tempProp = "";
foreach (string x in propnumList)
{
if (x.Length < 30)
{
x.Equals(null);
}
else
{
tempProp = x.Substring(31);
using (StreamWriter write = new StreamWriter("PROPNUMTEST.txt"))
{
write.WriteLine(tempProp); WANT TO RETURN MORE THAN JUST LAST ITEM
}
}
}
헤드 업 경고 : 'x.Equals (null);' 'x'가 항상 null의 경우, null 참조 예외를 슬로우합니다. – Caleb