• C# arrayList动态添加对象元素,并取出对象元素的方法


    先建一个类,类中有两个变量作为坐标值

    public class remtbpoint //remtbpoint 类(用来记忆某对象坐标)
    {
    private int rpointline;
    private int rpointcol;
    {
    get { return rpointline; }
    set { rpointline = value; }
    }
    public int RPointcol
    {
    get { return rpointcol; }
    set { rpointcol = value; }
    }
    }

    在主程序中定义arrayList

    ArrayList rembtpointLinst = new ArrayList();

    在子程序中添加坐标值到arrayList中和从arrayList中取出值

    View Code
    1 private void rempoint(int line,int col) //记忆子程序,实例化后,赋值,加到arrayList中
    2   {
    3 remtbpoint r1 = new remtbpoint();
    4 r1.RPointLine = line;
    5 r1.RPointcol = col;
    6 rembtpointLinst.Add(r1);
    7 }
    8
    9
    10 private void button1_Click(object sender, EventArgs e)//从记忆的arrayList中取出值,并动态删除最后一个arrayList元素
    11   {
    12 int x = rembtpointLinst.Count;//直接取最末元素
    13 if (x >= 1)
    14 {
    15 remtbpoint r3 = rembtpointLinst[x - 1] as remtbpoint;//-------对于取数组列表中某元素太难,用这个方法极好用
    16 //do...(r3.RPointLine, r3.RPointcol);这里就可以把arrayList元素对应的坐标值传给其它子程序使用了.
    17 rembtpointLinst.RemoveAt(x - 1);
    18 }
    19 }
    很简单,但很实用,呵呵
  • 相关阅读:
    领域建模
    中科院
    开放搜索服务OpenSearch
    GUIForDebug
    java: org.luaj.vm2.LuaError:XXX module not found lua脚本初始化出错(转)
    new TimerTask(robot)(转)
    lua-TestMore(转)
    Lua 数据库访问(转)
    推荐谈论高并发柱
    查看文章strncpy()功能更好的文章
  • 原文地址:https://www.cnblogs.com/dooroo/p/arrayList_use.html
Copyright © 2020-2023  润新知