如何动态地将值添加到数组中 [英] how to add values into array dynamically

查看:122
本文介绍了如何动态地将值添加到数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何动态地将值添加到数组中





你能给我提供代码吗?

how to add values into array dynamically


could you please provide me code?

推荐答案

我假设你的意图是通过一个或多个索引来增长数组 - 这是不可能的。您必须分配具有所需大小的新数组,并将旧数组的值复制到其中。参见 Array.Copy(..) [ ^ ]



也许你应该考虑使用一个标准的Collection-Classes,比如列表< t> [ ^ ]或适合您的任何内容。这些将自动处理底层存储的增长。
I assume your intention is to grow an array by one or more indices - that's not possible. You would have to allocate a new array that has the desired size and copy the values of the old array into it. See Array.Copy(..)[^]

Maybe you should consider using one of the standard Collection-Classes instead, like List<t>[^] or whatever would suit you. Those would handle growing the underlying storage automatically.


这篇关于如何动态地将值添加到数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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