標籤:style blog color for div re
using System;namespace ZhuaJiuNS { public class ZhuaJiu { public static void Main() { string[] namelist = null; CreateNameList(ref namelist); string[] afternamelist; Zhua(namelist, out afternamelist); PrintNameList(afternamelist); Console.ReadKey(); } public static void CreateNameList(ref string[] beforelist) { beforelist = new string[5]; beforelist[0] = "張三"; beforelist[1] = "李四"; beforelist[2] = "王五"; beforelist[3] = "趙六"; beforelist[4] = "孫七"; } public static void Zhua(string[] beforelist, out string[] afterlist) { afterlist = new string[1]; int tmpindex = -1; System.Random ran = new Random(); if (beforelist.Length > 0) { Console.WriteLine("開始抓鬮了:"); int tmplength = beforelist.Length; for (int i = 0; i < tmplength; i++) { Console.WriteLine("請斷行符號進行抓鬮"); Console.ReadLine(); tmpindex = ran.Next(0, beforelist.Length); Console.WriteLine("本次抓到的人為" + beforelist[tmpindex]); InsertAfterList(beforelist[tmpindex], ref afterlist); RemoveFromBeforeList(tmpindex, ref beforelist); } Console.WriteLine("抓鬮結束"); } } public static void InsertAfterList(string insertname, ref string[] afterlist) { afterlist[afterlist.Length - 1] = insertname; string[] longlist = new string[(afterlist.Length + 1)]; for (int i = 0; i < afterlist.Length; i++) { longlist[i] = afterlist[i]; } afterlist = longlist; longlist = null; } public static void RemoveFromBeforeList(int removeindex, ref string[] beforelist) { if (removeindex == (beforelist.Length - 1)) { beforelist[removeindex] = ""; } else { int i = 0; for (i = removeindex; i < (beforelist.Length - 1); i++) { beforelist[i] = beforelist[i + 1]; } } if (beforelist.Length > 1) { string[] shortlist = new string[(beforelist.Length - 1)]; for (int i = 0; i < beforelist.Length - 1; i++) { shortlist[i] = beforelist[i]; } beforelist = shortlist; shortlist = null; } else { beforelist = null; } } public static void PrintNameList(string[] list) { Console.WriteLine("下面輸出人員列表:"); for (int i = 0; i < list.Length; i++) { Console.Write(list[i] + "\t"); } Console.WriteLine(); Console.WriteLine("輸出人員列表結束"); } }}