是否可以使用SPECEFIC NO定义自定义类型数组.成员并在运行时扩展它? [英] Is it possible to define a custom type array WITH SPECEFIC NO. OF MEMBERS and EXTEND IT in the run time?

查看:97
本文介绍了是否可以使用SPECEFIC NO定义自定义类型数组.成员并在运行时扩展它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友:

是否可以定义自定义类型的数组,例如具有特定编号的长数组.元素(例如5)并在运行时追加其成员并将此数组扩展到例如9个成员?

Yours

解决方案

为什么不使用列表 [^ ]?推荐这样做.

就调整数组大小而言.看这里:

http://msdn.microsoft.com/en-us/library/1ffy6686 (v = vs.80).aspx [Array.Resize<t> [ ^ ]方法.

但是,如果元素的数量未知,则在大多数情况下,我宁愿使用 List< t> [ ^ ]

您当然可以使用Linq:

  var  s =  字符串 [] {"  " " };
 var  s2 = s.Concat( 字符串 [] {" }).ToArray(); 



或用于空白数组

  var  s =  字符串 [] {"  " " };
 var  s2 = s.Concat( 字符串 [ 5 ]).ToArray(); 



其他解决方案也可以使用,并且可能更快,但是如果您组合数组,Linq可能更好.


dear BUDDIES:

Is it possible to define a custom type array such as long array with specefic no. of elements such as 5 and in the run time append its member and extend this array to forexample 9 members?

Yours

解决方案

Why not use List[^]? This is more recommended.

As far as resizing the array is concerned. Look here:

http://msdn.microsoft.com/en-us/library/1ffy6686(v=vs.80).aspx[^]


Yes, you can use for example Array.Resize<t>[^] method for this.

However if the amount of elements is unknown, in most scenarios I''d prefer using a List<t>[^]


Of course you can use Linq:

var s =  new string[] { "a", "b", "c" };
var s2 = s.Concat(new string[] { "V" }).ToArray();



or for blank array

var s =  new string[] { "a", "b", "c" };
var s2 = s.Concat(new string[5]).ToArray();



Other solutions also work, and probably faster, but if you are combining arrays, Linq is probably better.


这篇关于是否可以使用SPECEFIC NO定义自定义类型数组.成员并在运行时扩展它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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