Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 解释代码_C#_Silverlight - Fatal编程技术网

C# 解释代码

C# 解释代码,c#,silverlight,C#,Silverlight,嗨,任何人都可以解释这些代码行,我需要了解它是如何工作的,以便继续我正在做的事情 if (e.Error == null){ Stream responseStream = e.Result; StreamReader responseReader = new StreamReader(responseStream); string response = responseReader.ReadToEnd(); string[] split1 = Regex.Sp

嗨,任何人都可以解释这些代码行,我需要了解它是如何工作的,以便继续我正在做的事情

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);
}
if(e.Error==null){
流响应流=e.结果;
StreamReader responseReader=新的StreamReader(responseStream);
字符串响应=responseReader.ReadToEnd();
string[]split1=Regex.Split(响应,“},{”);
列表优先级1=新列表(拆分1);
pri1.RemoveAt(0);
字符串last=pri1[pri1.Count()-1];
pri1.移除(最后一个);
}

据我所见,它正在读取一个可能来自TCP的流。 它读取整个数据块,然后使用分隔符
},{
分隔数据块

因此,如果您有类似于abc},{dec,它将被放入具有2个值的split1数组中,split1[0]=abc,split1[1]=dec


在那之后,它基本上从我看到的内容中删除了第一个和最后一个内容,它是从一个可能来自TCP的流中读取的。 它读取整个数据块,然后使用分隔符
},{
分隔数据块

因此,如果您有类似于abc},{dec,它将被放入具有2个值的split1数组中,split1[0]=abc,split1[1]=dec


之后,它基本上删除了第一个和最后一个内容,它正在处理一个错误输出。 它从e接收到一个流(我想这是一个例外),读取它。 它看起来像: “{DDD},{I failed},{因为},{没有信号}{ENDCODE}”
它将其拆分为不同的字符串,并删除第一个和最后一个条目(DDD、ENDCODE)

它正在处理错误输出。 它从e接收到一个流(我想这是一个例外),读取它。 它看起来像: “{DDD},{I failed},{因为},{没有信号}{ENDCODE}”
它将其拆分为不同的字符串,并删除第一个和最后一个条目(DDD,ENDCODE)

它将响应流作为字符串读取,假设该字符串由逗号分隔的序列“{…}”组成,例如:

{十} ,{Y},{Z}

然后拆分“},{”上的字符串,给出

{X

Y

Z}


然后从数组的第一个元素({X=>X)中删除第一个大括号,并从数组的最后一个元素(Z}=>Z)中删除最后一个大括号。

它将响应流作为字符串读取,假设该字符串包含由逗号分隔的序列“{…}”,例如:

{十} ,{Y},{Z}

然后拆分“},{”上的字符串,给出

{X

Y

Z}

然后从数组的第一个元素({X=>X)中删除第一个大括号,并从数组的最后一个元素(Z}=>Z)中删除最后一个大括号。

//检查是否没有错误
如果(e.Error==null)
{
//流是从某处读/写信息的一种方式
//无需管理缓冲区分配等
流响应流=e.结果;
//StreamReader是一个使从流中读取更容易的类
StreamReader responseReader=新的StreamReader(responseStream);
//读取写入流的所有内容,并使用
//为流/读取器指定的字符编码。
字符串响应=responseReader.ReadToEnd();
//使用“},{”作为分隔符创建字符串数组
//string.Split将更加高效和简单。
string[]split1=Regex.Split(响应,“},{”);
//创建数组的列表。列表使使用数组更容易
//因为您不必手动移动元素或进行分配
列表优先级1=新列表(拆分1);
pri1.RemoveAt(0);
//获取数组中的最后一项。使用.Length会更有效
//计数的计数()
字符串last=pri1[pri1.Count()-1];
//删除最后一项
pri1.移除(最后一个);
}
如果唯一要做的就是删除第一个和最后一个元素,我会使用
LinkedList
而不是
List

//检查是否没有错误
如果(e.Error==null)
{
//流是从某处读/写信息的一种方式
//无需管理缓冲区分配等
流响应流=e.结果;
//StreamReader是一个使从流中读取更容易的类
StreamReader responseReader=新的StreamReader(responseStream);
//读取写入流的所有内容,并使用
//为流/读取器指定的字符编码。
字符串响应=responseReader.ReadToEnd();
//使用“},{”作为分隔符创建字符串数组
//string.Split将更加高效和简单。
string[]split1=Regex.Split(响应,“},{”);
//创建数组的列表。列表使使用数组更容易
//因为您不必手动移动元素或进行分配
列表优先级1=新列表(拆分1);
pri1.RemoveAt(0);
//获取数组中的最后一项。使用.Length会更有效
//计数的计数()
字符串last=pri1[pri1.Count()-1];
//删除最后一项
pri1.移除(最后一个);
}

如果唯一要做的就是删除第一个和最后一个元素,我会使用
LinkedList
而不是
List

哪些行你不懂?哪些行你不懂?逻辑上它应该删除大括号,但从代码上看,似乎不是这样。它似乎在删除整个{X和Z}从逻辑上讲,它应该删除大括号,但从代码上看,它似乎不是这样。它似乎在删除整个{X和Z}split1是一个字符串数组。如果响应包含
{a},{b},{c}
,则会得到一个带有
“{a”,“b”,“c}”
”的数组,这让我觉得您需要执行
字符串[]split1=response.Trim('{','}').Split(new[]{{},{},StringSplitOptions.None)
而不是下面的所有行,因为它将为您提供
“a”、“b”、“c”
。不要询问
// 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);
     }