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");
  • 相关阅读:
    A1066 Root of AVL Tree (25 分)
    A1099 Build A Binary Search Tree (30 分)
    A1043 Is It a Binary Search Tree (25 分) ——PA, 24/25, 先记录思路
    A1079; A1090; A1004:一般树遍历
    A1053 Path of Equal Weight (30 分)
    A1086 Tree Traversals Again (25 分)
    A1020 Tree Traversals (25 分)
    A1091 Acute Stroke (30 分)
    A1103 Integer Factorization (30 分)
    A1032 Sharing (25 分)
  • 原文地址:https://www.cnblogs.com/perfect/p/1207707.html
Copyright © 2011-2022 走看看