using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;//arraylist派生于array类
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
//学习arraylist
string[] name1 = new string[] { "a", "b", "c" };
//array类位于System命名空间中
Array.Sort(name1);
//输出数组的元素
foreach (string subname in name1)
{
Console.WriteLine(subname);
}
//在foreach中使用break,直接退出foreach语句 这样最终只显示a
foreach (string subname in name1)
{
if (subname=="b")
{
break;
}
Console.WriteLine(subname);
}
//在foreach中使用continue,直接进行下一次循环
foreach (string subname in name1)
{
if (subname == "a")
{
continue;
}
Console.WriteLine(subname);
}
string inputstr=Console.ReadLine();
if (inputstr == "abc")
{
Console.WriteLine("输入字符是abc");
}
Console.WriteLine(inputstr);
Console.ReadKey();
//学习arraylist类
ArrayList al1 = new ArrayList(4);
al1.Add("arraylist的元素1");
al1.Add(1);
al1.Add(true);
Console.WriteLine(al1.Count);
Console.WriteLine(al1.Capacity);
al1.Insert(3, "翟勋杨");
al1.Remove(true);
al1.Clear();
Console.WriteLine("运行clear后"+al1.Count);
Console.ReadKey();
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9240380/viewspace-718831/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/9240380/viewspace-718831/