. net数组输出

本文关键字:输出 数组 net | 更新日期: 2023-09-27 18:17:04

我有一个很基本的问题,但是我想不出来。(几乎周末;P)我有这个函数ReadOpenCalls(int relation),它从一个关系中获得开放调用。

List<string> messages = new List<string>();
if (inboundSet != null && inboundSet.RecordCount > 0)
{
    inboundSet.MoveFirst();
    do
    {
        messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString());
        messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString());
        inboundSet.MoveNext();
    }
    while (!inboundSet.EOF);
    return messages;
}

通过WCF调用到PHP页面。现在一切都运行良好,我唯一的问题是它的输出:

stdClass Object ( [string] => Array ( [0] => Webservice [1] => 1004 [2] => Webservice [3] => 1005 [4] => Webservice [5] => 1006 [6] => Webservice [7] => 1007 [8] => Webservice [9] => 1008 [10] => Webservice [11] => 1009 [12] => Webservice [13] => 1010 [14] => Webservice [15] => 1011 ) )

我真的希望输出的"Webservice和ID"在这个例子中是在一起的,而不是在一个大数组中。

比如

[0] => Webservice,
       1004
[1] => Webservice,
       1005

请给我一些例子或一个好的方向的镜头。之后我请你喝杯啤酒

. net数组输出

而不是像下面这样两次调用Add方法:

 do
 {
    messages.Add(inboundSet.Fields["DESCRIPTION"].Value.ToString());
    messages.Add(inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString());
    inboundSet.MoveNext();
 }

只需在每次迭代中调用一次,并在值中添加

 do
 {
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString();
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()
    messages.Add(desc  +", "+inboundMsg );
    inboundSet.MoveNext();
 }

如果需要换行,那么这样做:

 do
 {
    string desc = inboundSet.Fields["DESCRIPTION"].Value.ToString();
    string inboundMsg = inboundSet.Fields["PK_R_INBOUNDMESSAGE"].Value.ToString()
    messages.Add(desc  +",'n"+inboundMsg );
    inboundSet.MoveNext();
 }