我正在创建一个列表,并希望设置添加到列表中的项目的值,然后检索该值以显示。
// Create a list of strings
List<string> AuthorList = new List<string>();
AuthorList.Add("AA");
AuthorList.Add("BB");
AuthorList.Add("CC");
AuthorList.Add("DD");
AuthorList.Add("EE");
// Set Item value
AuthorList["AA"] = 20;
// Get Item value
Int16 age = Convert.ToInt16(AuthorList["AA"]);
// Get first item of a List
string auth = AuthorList[0];
Console.WriteLine(auth);
// Set first item of a List
AuthorList[0] = "New Author";
但是发生了错误
“'System.Collections.Generic.List.this[int]' 的最佳重载方法匹配有一些无效参数”
帮助我更正此代码。