首先,声明SortedList类-
SortedList list = new SortedList();
现在添加值-
list.Add("S1", "Wallets"); list.Add("S2", "Sunglasses"); list.Add("S3", "Backpacks");
以下是与SortedList类的Values属性一起使用的代码-
using System; using System.Collections; namespace Demo { class Program { static void Main(string[] args) { SortedList list = new SortedList(); list.Add("S1", "Wallets"); list.Add("S2", "Sunglasses"); list.Add("S3", "Backpacks"); foreach (string value in list.Values) { Console.WriteLine(value); } } } }
输出结果
Wallets Sunglasses Backpacks