zoukankan      html  css  js  c++  java
  • 关于 List 泛型集合访问方法

    坛友问:

            //定义存储每个柱子上可移动标签的泛型集合
            List<List<Label>> seleckedCanMoveLb = new List<List<Label>>();
            for (int i = 0; i < 3; i++)
            {
                seleckedCanMoveLb = new List<Label>();
            }

            for (int i = 0; i < seleckedCanMoveLb.Count; i++)
           {
                 seleckedCanMoveLb
           }
        for (int i = 0; i < seleckedCanMoveLb.Count; i++)
           {
                 seleckedCanMoveLb
            }

    都不对,应该如何访问List集合中的元素?


    答:

                List<System.Windows.Forms.Label> pLabelList = new List<System.Windows.Forms.Label>();
                pLabelList.Add(this.label1);
                pLabelList.Add(this.label2);
                ////方法一:
                <span style="color:#ff0000;">foreach (System.Windows.Forms.Label pLabel in pLabelList)</span>
                {
                    string sName = pLabel.Name;
                }
                ///方法二:你基础太不扎实了,最基本的语法还是要好好看的
                <span style="color:#ff6666;">for (int i = 0; i < pLabelList.Count; i++)</span>
                {
                    System.Windows.Forms.Label pLabel = pLabelList[i];
                    string sName = pLabel.Name;
                }


  • 相关阅读:
    poj 1584
    poj 1113 & poj 2187
    pku 1321 棋盘问题
    poj 1408
    pku 2251 Dungeon Master
    sdut oj 2218 Give Me an E
    Android工程 单元测试
    Android Timer编写方式
    去除工程的.svn隐藏文件夹
    Android 绑定远程服务出现 Not Allowed to bind service
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/4258657.html
Copyright © 2011-2022 走看看