如何在收藏夹中添加新项目. [英] How to add new items in collection.

查看:81
本文介绍了如何在收藏夹中添加新项目.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个已经有3个项目的集合对象.我想在每3个项目中添加一个额外的字段.该怎么做?

Hi,

i have one collection object which allready having 3 items .i want to add one extra field in each 3 item.How to do it ?

Thanks

推荐答案

您不能向集合中的项目添加字段-您需要将该字段添加到项目的定义中,然后它将自动为在您添加的每个项目中.通常,您是在设计时而不是运行时执行的.

您要在这里实现什么?
You can''t add a field to items in a collection - you need to add the field to the definition of the item, then it will automatically be in each item you add. Normally, you do this at design time, not run time.

What are you trying to achieve here?



请参阅此链接

将项目添加到集合 [
hi
refer this link

Add items to collection[^]


您好,

试试这个:

Hi there,

try this:

IEnumerable<string> ReadLines()
{
     string s;
     do
     {
          s = Console.ReadLine();
          yield return s;
     } while (s != "");
}

IEnumerable<string> lines = ReadLines();
lines.Add("foo") // so what would this supposed to do??


但是,您可以做的是创建一个新的IEnumerable对象(未指定类型),该对象枚举时将提供旧对象的所有项目,以及您自己的一些项目.为此,您可以使用Enumerable.Concat:


What you can do, however, is creating a new IEnumerable object (of unspecified type), which, when enumerated, will provide all items of the old one, plus some of your own. You use Enumerable.Concat for that:

items = items.Concat(new[] { "foo" });


一切顺利.


All the best..


这篇关于如何在收藏夹中添加新项目.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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