嗨,谁能解释这些代码行,我需要了解它是如何工作的,以便继续我正在做的事情
if (e.Error == null){
Stream responseStream = e.Result;
StreamReader responseReader = new StreamReader(responseStream);
string response = responseReader.ReadToEnd();
string[] split1 = Regex.Split(response, "},{");
List<string> pri1 = new List<string>(split1);
pri1.RemoveAt(0);
string last = pri1[pri1.Count() - 1];
pri1.Remove(last);
}发布于 2011-05-25 15:34:15
// Check if there was no error
if (e.Error == null)
{
// Streams are a way to read/write information from/to somewhere
// without having to manage buffer allocation and such
Stream responseStream = e.Result;
// StreamReader is a class making it easier to read from a stream
StreamReader responseReader = new StreamReader(responseStream);
// read everything that was written to a stream and convert it to a string using
// the character encoding that was specified for the stream/reader.
string response = responseReader.ReadToEnd();
// create an array of the string by using "},{" as delimiter
// string.Split would be more efficient and more straightforward.
string[] split1 = Regex.Split(response, "},{");
// create a list of the array. Lists makes it easier to work with arrays
// since you do not have to move elements manually or take care of allocations
List<string> pri1 = new List<string>(split1);
pri1.RemoveAt(0);
// get the last item in the array. It would be more efficient to use .Length instead
// of Count()
string last = pri1[pri1.Count() - 1];
// remove the last item
pri1.Remove(last);
}如果唯一要做的就是删除第一个和最后一个元素,我会使用LinkedList而不是List。
发布于 2011-05-25 15:30:37
它将响应流作为字符串读取,假设字符串由逗号分隔的序列"{...}“组成,例如:
{X}、{Y}、{Z}
然后在"},{“上拆分字符串,给出一个
{X
是
Z}
然后从数组的第一个元素( {X => X)中删除第一个大括号,并从数组的最后一个元素( Z} => Z)中删除最后一个大括号。
发布于 2011-05-25 15:28:25
据我所见,它正在从可能来自TCP的流中读取数据。它读取整个数据块,然后使用分隔符},{分隔这些块。
所以如果你有像abc},{dec这样的东西,它将被放入带有2个值的split1数组中,split1 =abc,split1 1=dec。
在那之后,它基本上删除了第一个和最后一个内容
https://stackoverflow.com/questions/6120882
复制相似问题