C# “附加”一词是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1068725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the meaning of the word "Append"
提问by tintincutes
I'm in the middle in studying some code and I encountered this word "Append" and I don't understand what it does.
我正在研究一些代码,我遇到了“附加”这个词,我不明白它的作用。
Code:
代码:
public static void appendData(string data)
{
if (isRecording) sb.Append(data + Environment.NewLine);
}
What does append mean?
附加是什么意思?
采纳答案by John Saunders
The answer from ChrisF is correct as far as StringBuilder.Append is concerned.
就 StringBuilder.Append 而言,ChrisF 的回答是正确的。
In general, the word "Append" means "to add to the end of". See http://en.wiktionary.org/wiki/append.
一般而言,“Append”一词的意思是“添加到”的末尾。请参阅http://en.wiktionary.org/wiki/append。
回答by ChrisF
I would guess that sb
is of type StringBuilder
.
我猜那sb
是类型StringBuilder
。
Append()
adds the supplied string to the end of the string being built in the StringBuilder
variable.
Append()
将提供的字符串添加到StringBuilder
变量中正在构建的字符串的末尾。
回答by James
It will add the string representation of the object to end of the string builder instance. It basically calls the .ToString() method of whatever object you pass in and concatenates it to the end of the internal string being build up.
它将对象的字符串表示添加到字符串构建器实例的末尾。它基本上调用您传入的任何对象的 .ToString() 方法,并将其连接到正在构建的内部字符串的末尾。
请参阅MSDN 文档
回答by chinna
This is quite simple. Then code above is simply "adding" or "appending" the variables/text supplied within the brackets to the variable "sb".
这很简单。然后上面的代码只是将括号内提供的变量/文本“添加”或“附加”到变量“sb”。
Append can be found as part of the System.Text.StringBuilder
class which I believe is being used above.
Append 可以作为System.Text.StringBuilder
我认为上面使用的类的一部分找到。
More info can be found following this link: StringBuilder
Class
可以通过以下链接找到更多信息:StringBuilder
Class
Happy coding!
快乐编码!
回答by Simon Gill
I would point out that the "right" way to do that bit of code is:
我要指出的是,执行那段代码的“正确”方法是:
public static void appendData(string data)
{
if (isRecording)
{
sb.Append(data);
sb.Append(Environment.NewLine);
}
}
Append is doing the same job as string1 + string2 but it is doing it in a much more efficient manner. Look up "Immutable Strings C#" for some more details if you need them.
Append 与 string1 + string2 做同样的工作,但它以更有效的方式完成。如果需要,请查阅“Immutable Strings C#”以获取更多详细信息。
回答by RichardOD
Assuming you are using Visual Studio put your cursor on the word Append and Press F1, you'll probably see something like this. If you are considering refactoring this and assuming it is using a StringBuilder, you might also want to read about AppendLine.
假设您使用的是 Visual Studio,将光标放在单词 Append 上并按 F1,您可能会看到类似这样的内容。如果您正在考虑重构它并假设它使用的是 StringBuilder,您可能还想阅读AppendLine。