Created
March 11, 2013 00:29
-
-
Save andyyou/5131165 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace AryList | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
int[] ar = new int[] { 1, 2, 3 }; | |
Console.WriteLine("1. ====Show int[]==== "); | |
foreach(var i in ar) | |
Console.WriteLine(i); | |
ArrayList alist = new ArrayList(); | |
int x = 0; | |
decimal y = 100m; | |
alist.Add(100); | |
alist.Add("string"); | |
alist.Add(10); | |
alist.Add(y); | |
Console.WriteLine("2. ====Show ArrayList each type===="); | |
Console.WriteLine("Displayed ArrayList sub object type directly"); | |
Console.WriteLine("alist[0] type: {0}", alist[0].GetType()); | |
foreach (var i in alist) | |
{ | |
Console.WriteLine(i.GetType()); | |
if (i.GetType() == typeof(int)) | |
{ | |
x = x + (int)i; | |
} | |
} | |
Console.WriteLine(x); | |
List<int> list = new List<int>(); | |
list.Add(1); | |
list.Add(2); | |
list.Add(3); | |
Console.WriteLine("3. ====Show List===="); | |
foreach(var i in list) | |
Console.WriteLine(i); | |
Console.WriteLine("4. ====Show List===="); | |
Array ary = Array.CreateInstance(System.Type.GetType("System.Int32"), 3); | |
ary.SetValue(1, 0); | |
ary.SetValue(2, 1); | |
foreach(var i in ary) | |
Console.WriteLine(i); | |
System.Collections.Stack stack = new System.Collections.Stack(); | |
Console.WriteLine("5. ====Show Stack===="); | |
Console.WriteLine("===入堆疊==="); | |
foreach (string i in new string[3] { "我", "愛", "C#" }) | |
{ | |
stack.Push(i); | |
Console.Write(i); | |
} | |
Console.WriteLine(); | |
Console.WriteLine("===出堆疊==="); | |
// stack.Pop(); //取堆疊值並移除 | |
// stack.Peek(); //取堆疊值不移除 | |
foreach (string i in stack) | |
{ | |
Console.Write(i); | |
} | |
Console.WriteLine("6. ====Show Queue===="); | |
Queue queue = new Queue(); | |
Console.WriteLine("===入Queue==="); | |
foreach (string i in new string[] { "我", "愛", "C#" }) | |
{ | |
queue.Enqueue(i); | |
Console.Write(i); | |
} | |
Console.WriteLine(""); | |
Console.WriteLine("===出Queue==="); | |
queue.Dequeue(); | |
queue.Peek(); | |
foreach (var i in queue) | |
{ | |
Console.Write(i); | |
} | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment