如何从另一个 class 访问唯一的子列表
How to access unique sublist from another class
我有一个列表列表,我想访问例如第二个子列表并添加一个字符串。
public static List<List<string>> logsIP1 = new List<List<string>>();
public static void logsList()
{
logsIP1.Add(new List<string> { });
logsIP1.Add(new List<string> { });
logsIP1.Add(new List<string> { });
}
我想要
Logs.logsIP1.Add(List<string>[0]("test");
试试这样的东西:
public static List<List<string>> logsIP1 = new List<List<string>>();
public static void Add(int index, string value)
{
var nestedList = logsIP1[index];
nestedList.Add(value);
}
然后你可以使用方法Add()
通过主列表的索引向嵌套列表中插入新值
I want access, for example, the second list and add strings from another class
把它分成两部分。首先,您需要访问外部列表中的第二项。要访问索引中的项目,您将使用:
List<string> second = logsIP1[1];
现在您有对第二个列表的引用并可以向其中添加项目:
second.Add("one");
second.Add("two");
我有一个列表列表,我想访问例如第二个子列表并添加一个字符串。
public static List<List<string>> logsIP1 = new List<List<string>>();
public static void logsList()
{
logsIP1.Add(new List<string> { });
logsIP1.Add(new List<string> { });
logsIP1.Add(new List<string> { });
}
我想要
Logs.logsIP1.Add(List<string>[0]("test");
试试这样的东西:
public static List<List<string>> logsIP1 = new List<List<string>>();
public static void Add(int index, string value)
{
var nestedList = logsIP1[index];
nestedList.Add(value);
}
然后你可以使用方法Add()
通过主列表的索引向嵌套列表中插入新值
I want access, for example, the second list and add strings from another class
把它分成两部分。首先,您需要访问外部列表中的第二项。要访问索引中的项目,您将使用:
List<string> second = logsIP1[1];
现在您有对第二个列表的引用并可以向其中添加项目:
second.Add("one");
second.Add("two");