小编ped*_*uiz的帖子

StringBuilder或+ =

我每秒收到大约5条消息.它们中的每一个都有一个字符串,我将其连接到一个包含所有收到的消息的主字符串

    string _masterText = "";
    public void AddNewMessage(string text)  // this is going to be call at least 5 times/second
    {
        _masterText += text;    
    }
Run Code Online (Sandbox Code Playgroud)

这是合适的方式吗?或者我应该使用StringBuilder,如:

    StringBuilder _masterText = new StringBuilder();
    public void AddNewMessage(string text) // this is going to be call at least 5 times/second
    {
         _masterText.Append(text);  
    }
Run Code Online (Sandbox Code Playgroud)

谢谢

.net stringbuilder string-concatenation

10
推荐指数
2
解决办法
1226
查看次数

Python if语句"SyntaxError:invalid syntax"

试图执行某人的代码,得到语法错误.不知道为什么:(

def GetParsers( self, systags ):
    childparsers = reduce( lambda a,b : a+b, [[]] + [ plugin.GetParsers( systags ) for plugin in self.plugins ] )
    parsers = [ p for plist in [ self.parsers[t] for t in systags if self.parsers.has_key(t) ] for p in plist ]
    return reduce( lambda a,b : ( a+[b] if not b in a else a ), [[]] + parsers + childparsers )
Run Code Online (Sandbox Code Playgroud)

错误是

File "base.py", line 100
    return reduce( lambda a,b : ( a+[b] if …
Run Code Online (Sandbox Code Playgroud)

python syntax-error

0
推荐指数
1
解决办法
3606
查看次数