ArrayList / Stack / Queue / List 使用方法及出現次序

 
ArrayList / Stack / Queue / List 使用方法及出現次序
 

   Default.aspx
 
   <asp:Table ID="Table1" runat="server">
 
      <asp:TableRow>
      <asp:TableCell Width="120">
      <asp:Label ID="Label1" runat="server" Text="">
      </asp:Label></asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label2" runat="server" Text="">
      </asp:Label></asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label3" runat="server" Text="">
      </asp:Label></asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label4" runat="server" Text="">
      </asp:Label></asp:TableCell>
      </asp:TableRow>
 
      <asp:TableRow>
      <asp:TableCell Width="120">
      <asp:Label ID="Label5" runat="server" Text="FIFO" Font-Bold="True" />
      </asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label6" runat="server" Text="LIFO" Font-Bold="True" />
      </asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label7" runat="server" Text="FIFO" Font-Bold="True" />
      </asp:TableCell>
      <asp:TableCell Width="120">
      <asp:Label ID="Label8" runat="server" Text="FIFO" Font-Bold="True" />
      </asp:TableCell>
      </asp:TableRow>
 
   </asp:Table>
 

 

   Default.aspx.cs
 
   private void datatableuse()
   {
 
      ArrayList A = new ArrayList();
      A.Add("1A");
      A.Add("2A");
      A.Add("3A");
      A.Add("4B");
      A.Add("5B");
      A.Add("6B");
      A.Add("7C");
      A.Add("9C");
 
      Label1.Text = "<B>ArrayList : </B><BR>";
 
      foreach (var s in A){
         Label1.Text += s.ToString() + "<BR>";
      }
 
      Stack B = new Stack();
      B.Push("1A");
      B.Push("2A");
      B.Push("3A");
      B.Push("4B");
      B.Push("5B");
      B.Push("6B");
      B.Push("7C");
      B.Push("8C");
      B.Push("9C");
 
      Label2.Text = "<B>Stack : </B><BR>";
 
      foreach (var s in B){
         Label2.Text += s.ToString() + "<BR>";
      }
 
      Queue C = new Queue();
      C.Enqueue("1A");
      C.Enqueue("2A");
      C.Enqueue("3A");
      C.Enqueue("4B");
      C.Enqueue("5B");
      C.Enqueue("6B");
      C.Enqueue("7C");
      C.Enqueue("8C");
      C.Enqueue("9C");
 
      Label3.Text = "<B>Queue : </B><BR>";
 
      foreach (var s in C){
         Label3.Text += s.ToString() + "<BR>";
      }
 
      List<String> D = new List<String>();
      D.Add("1A");
      D.Add("2A");
      D.Add("3A");
      D.Add("4B");
      D.Add("5B");
      D.Add("6B");
      D.Add("7C");
      D.Add("8C");
      D.Add("9C");
 
      Label4.Text = "<B>List : </B><BR>";
 
      foreach (var s in D){
         Label4.Text += s.ToString() + "<BR>";
      }
 
   }