zoukankan      html  css  js  c++  java
  • 获取ArrayList中的数据(foreach)

            public class PositionData
            {
                
    private string name; //字段
                private string ticker;//字段
                private string shares;//字段

                
    public PositionData()
                {

                }

                
    public PositionData(string name, string ticker, string shares)
                {
                    
    this.name = name;
                    
    this.ticker = ticker;
                    
    this.shares = shares;
                }

                
    public string Name //属性
                {
                    
    get
                    {
                        
    return name;
                    }
                }

                
    public string Ticker //属性
                {
                    
    get
                    {
                        
    return ticker;
                    }
                }

                
    public string Shares //属性
                {
                    
    get
                    {
                        
    return shares;
                    }
                }
            }

            ArrayList values 
    = new ArrayList();
            values.Add(
    new PositionData("Microsoft""Msft""150 共享")); 
            values.Add(
    new PositionData("Intel""Intc""25 共享")); 
            values.Add(
    new PositionData("Dell""Dell""115 共享"));
            
    foreach (PositionData da in values)
            {
               
    if (da.Name == "Microsoft")
                  MessageBox.Show(da.Name.ToString()
    +" "+da.Ticker.ToString()+" "+da.Shares.ToString(),"Info");
            }



    //******************************使用泛******************************//
            
        List
    <PositionData> tmp = new List<PositionData>();
            tmp.Add(
    new PositionData("Microsoft""Msft""150 共享"));
            tmp.Add(
    new PositionData("Intel""Intc""25 共享"));
            tmp.Add(
    new PositionData("Dell""Dell""115 共享"));
            
    for (int i = 0; i < tmp.Count; i++)
                MessageBox.Show(tmp[i].Name 
    + " " + tmp[i].Ticker + " " + tmp[i].Shares, "Info");
  • 相关阅读:
    macOS 遇到 svnadmin无法使用的情况
    语音识别进化简史:从造技术到建系统
    你是什么垃圾?人工智能面对干垃圾和湿垃圾“有点蒙”
    垃圾分类的事,让机器人做去吧!
    怎样才能叫一只奶牛自愿挤奶?
    第一次,脑机接口可以实时读取人类语言了
    机器人工作原理的超详细解析,生动、形象!
    1900页数学基础:面向CS的线性代数、拓扑、微积分和最优化
    微软Azure AI负责人:OpenAI只在微软云上训练模型
    Velodyne收购高清地图公司 将研发更安全的ADAS系统
  • 原文地址:https://www.cnblogs.com/perfect/p/1207707.html
Copyright © 2011-2022 走看看