我只是想循环所有
results 对象中的 items[x] (返回我拥有的这个对象的函数,它基本上只返回一个字符串列表)。这来自我为 Web 服务目的创建的 vb.net 函数。我认为做一个 foreach 循环会是最简单最有效的事情,但我不能这样做,因为我的类没有实现 IEnumerable。但是我想知道是否还有更简单的方法可以在不使用 iEnumerable 的情况下循环它。您的帮助将不胜感激。这就是我的函数返回的类的样子。
Public Class GetErrors
Public FWWDIR_ERR_VENDOR As String = String.Empty
Public FWWDIR_ERR_INVOICE As String = String.Empty
Public FWWDIR_ERR_ACCOUNT As String = String.Empty
Public FWWDIR_ERR_FUND As String = String.Empty
Public FWWDIR_ERR_ORGN As String = String.Empty
Public FWWDIR_ERR_PROG As String = String.Empty
Public FWWDIR_ERR_ADDRSS_TYP As String = String.Empty
Public FWWDIR_ERR_ADDRSS_SEQ As String = String.Empty
Public FWWDIR_ERR_LOCATION As String = String.Empty
Public FWWDIR_ERR_ACTIVITY As String = String.Empty
Public FWWDIR_ROW As String = String.Empty
Public service_error As String = String.Empty
Public FWWDIR_ERR_PO As String = String.Empty
Public FWWDIR_ERR_CHKVEND As String = String.Empty
Public FWWDIR_ERR_FSYR As String = String.Empty
Public FWWDIR_ERR_FSPD As String = String.Empty
Public FWWDIR_ERR_ONTM_VEND As String = String.Empty
Public FWWDIR_ERR_ONTM_ADRS1 As String = String.Empty
Public FWWDIR_ERR_ONTM_CITY As String = String.Empty
Public FWWDIR_ERR_ONTM_STATE As String = String.Empty
Public FWWDIR_ERR_ONTM_ZIP As String = String.Empty
Public FWWDIR_ERR_ENCUM_AMT As String = String.Empty
Public FWWDIR_ERR_ENCUM_VEND As String = String.Empty
Public FWWDIR_ERR_ITEM_ERROR As String = String.Empty
Public FWWDIR_POHD As String = String.Empty
End Class
我试过的短代码片段。
ServiceApUtils _apUtils = new ServiceApUtils();
var results = _apUtils.ADP_Processor(l_taxcode.ToArray(), l_amount.ToArray(), l_row.ToArray());
//Response.Write(results[0].)
if (results[0].service_error!="")
{
Response.Write(results[0].service_error);
}
else if (results.Count > 0)//
{
for (int x = 0; x < results.Count; x++ ) //typecast x a get error to loop the results
{
TableRow tr = new TableRow();
Table1.Rows.Add(tr);
foreach (string value in results[x])//fails here with Ienumerable error
{
TableCell tc = new TableCell();
tc.Text = results[x].FWWDIR_ROW + results[x].FWWDIR_ERR_INVOICE + results[x].FWWDIR_ERR_ACCOUNT;
tr.Cells.Add(tc);// = new TableCell();
}
}
}
无论我尝试 iEnumerable 错误还是我根本不知道如何在每个数组项内循环,我都会收到错误。
使用类作为返回的函数正在执行此操作
Public Function ADP_Processor(
ByVal w_taxcode As String(), _
ByVal w_Amount As String(), _
ByVal w_row As String()) As List(Of GetErrors)