C# (Program.cs):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | using System; using System.Collections.Generic; namespace MultiList { class Program { static void Main( string [] args) { //建立一維List List<String> titles = new List<String>() { "ChatBoxy" , "CodeBoxy" , "ToolBoxy" }; //建立一維List List<String> websites = new List<String>() { "http://chatboxy.blogspot.com/" , "http://codeboxy.blogspot.com/" , "http://toolboxy.blogspot.com/" }; //建立多維List關係 List<List<String>> options = new List<List<String>> { titles, websites }; //新增QQBoxy資料 titles.Add( "QQBoxy" ); websites.Add( "http://qqboxy.blogspot.com/" ); //移除ChatBoxy資料 titles.Remove( "ToolBoxy" ); websites.Remove( "http://toolboxy.blogspot.com/" ); //移除第0筆資料 titles.RemoveAt(0); websites.RemoveAt(0); //印出資料 foreach (List<String> value in options) { foreach (var v in value) { Console.WriteLine(v); } } } } } |
結果:
說明:
C#多維List新增移除資料後印出內容。