【发布时间】:2020-07-16 05:37:37
【问题描述】:
我正在使用 C# System.Collections.Generic List 并且 Add 函数按预期工作,但 Append 什么都不做?为什么是这样?我觉得我遗漏了一些明显的东西,但我看不到什么,我使用它与 Add 相同,但它不起作用?
List<string> x = new List<string>();
x.Add("hello");
foreach (string s in x) { Console.WriteLine(s); }
Console.WriteLine();
x.Add("hi");
foreach (string s in x) { Console.WriteLine(s); }
Console.WriteLine();
x.Append("oi");
foreach (string s in x) { Console.WriteLine(s); }
Console.WriteLine();
x.Append("aye");
foreach (string s in x) { Console.WriteLine(s); }
Console.WriteLine();
输出:
hello
hello
hi
hello
hi
hello
hi
【问题讨论】:
-
在线搜索 "c# SomeMethodName" 通常会将您带到文档中,找到无法按您期望的方式工作的方法。在那里您可以阅读有关如何使用它的信息。