如何在运行时在C#中命名列表集合 [英] how to name a list collection in c# at run time

查看:96
本文介绍了如何在运行时在C#中命名列表集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在运行时命名列表集合?

如果我想从字符串数组中填充名称并列出每个名称,即

我有一个数组courseList [i]

如果我想从表格中填充每个项目并为每个项目制作一个单独的列表.我应该使用什么方法?

List< string> ______ =新列表< string>();


我该如何动态填充______?

How do I name a list collection at run time?

If I want to populate names from a string array and make a list of each, i.e.

I have an array courseList[i]

If I want to populate each item form it and make a separate list of each. What approach Shall I use?

List<string> ______ = new List<string>();


How can I fill this ______ dynamically?

推荐答案

我不认为您可以这样做.您可能需要创建列表并将其添加到使用该名称作为键的某个集合类(例如Dictionary)中.
I don''t think you can do it this way. You probably need to create your lists and add them to some collection class (Dictionary for example) that uses the name as the key.


就像前面的答案一样,我不知道您是什么尝试完成,但是您也可以实现自己的命名集合,该集合仅从字符串列表派生,并向该类添加name属性.

Just like the previous answers, I do not know what you try to accomplish but you could also implement your own named collection that just derives from a list of strings and add a name property to the class.

public class NamedList : List<string>
{
  public string Name { get; set; }
}
</string>


听起来很痛苦,尽管可以肯定.

但是为什么不使用KeyValueCollection
每个元素都有键=名称(您想要的______)-和值=相应的List< string>.
Sounds painful, though could certainly be done.

But why not use KeyValueCollection
Each element has key = name (the ______ that you want) - and value = the corresponding List<string>.


这篇关于如何在运行时在C#中命名列表集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆