永发信息网

C# ArrayList如何动态添加对象及取值

答案:3  悬赏:0  手机版
解决时间 2021-01-23 08:02
C# ArrayList如何动态添加对象及取值
最佳答案
1 添加用add函数,
2 取值根据索引。用中括号例如 myAL[2],
using System;
using System.Collections;
public class SamplesArrayList {

public static void Main() {

// Creates and initializes a new ArrayList.
ArrayList myAL = new ArrayList();
myAL.Add("Hello");
myAL.Add("World");
myAL.Add("!");

// Displays the properties and values of the ArrayList.
Console.WriteLine( "myAL" );
Console.WriteLine( " Count: {0}", myAL.Count );
Console.WriteLine( " Capacity: {0}", myAL.Capacity );
Console.Write( " Values:" );
PrintValues( myAL );
}

public static void PrintValues( IEnumerable myList ) {
foreach ( Object obj in myList )
Console.Write( " {0}", obj );
Console.WriteLine();
}

}
全部回答
先建一个类,类中有两个变量作为坐标值 public class remtbpoint //remtbpoint 类(用来记忆某对象坐标){ private inprivate int rpointcol; public int RPointline{ get{return rpointline;} set { rpointline = value; }} public int RPointcol{get{ return rpointcol; } set { rpointcol = value; }}}private void rempoint(int line,int col)//记忆子程序,实例化后,赋值,加到arrayList中{r1 =new ;;; r1.RPointLine=line; r1.RPointcol=col; rembtpointLinst.Add(r1);} private void button1_Click(object sender,EventArgs e)//从记忆的arrayList中取出值,并动态删除最后一个arrayList元素{ int x=rembtpointLinst.Count;//直接取最末元素 if(x=1) {remtbpoint r3 =rembtpointLinst[x-1]asremtbpoint;//-------对于取数组列表中某元素太难,用这个方法极好用 //do...(r3.RPointLine, r3.RPointcol);这里就可以把arrayList元素对应的坐标值传给其它子程序使用了.
sb.add(name,courseid,value) 没有这个写法吧?arraylist类没有三个参数的add方法. sb.add(new string[]{name,courseid,value})才对吧? sb.add(new course (name,courseid,value)) 是往arraylist里加入一个course 的对象
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
狗狗打完血清后,第二天拉便便出现血粒.紧..
木木美甲地址在什么地方,想过去办事,
多美依。洗衣地址好找么,我有些事要过去,
中兴BA601. 总是跳屏是什么情况。求解答
V爱美甲会所地址有知道的么?有点事想过去!
济南南郊宾馆赵姓贱男辱人
喝什么样的酸奶好
对下面句子运用的修辞方法及其表达作用分析不
自已注册的文字商标能申请图形吗
爱美甲地址在什么地方,想过去办事,
伊蔻·洗衣(玉龙湾店)地址好找么,我有些
请问今年珠海小学入学何时报名,手续如何。
— Excuse me, can you spare me a few minut
在如图所示滑轮组中,每个滑轮质量相同,不计绳
艾卡尼欧式洗衣(黄石连锁)地址好找么,我有些
推荐资讯
万米金滩公寓(海阳海景路六店)地址在什么地方
s开头的社交软件名称 国外帅哥很多的那个
全民奇迹剑士以天灼为主精灵组合
有没有承受最小电压是1伏或更小的继电器?
DNF宠物使用技能会影响饲料消耗吗?
我电脑上面出现了一个文件“CoolEdi_2.1”,
人工养殖的老虎,能买到吗?
中国邮政(凤凰邮政所)(环北二路698号中国邮政
阅读下面短文,完成所给任务。Tom was three
平果国际大酒店停车场地址在哪,我要去那里办
已知a>b,下列关系式中一定正确的是A.-a>-b
广东特产(东莞富塘区7)地址在哪,我要去那里
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?