找到 2628 篇文章 关于 C#
68 次浏览
要从 OrderedDictionary 中删除所有元素,代码如下:示例 实时演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ OrderedDictionary dict = new OrderedDictionary(); dict.Add("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Smart Wearables"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("OrderedDictionary 元素..."); foreach(DictionaryEntry d in dict){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("元素数量..."); 阅读更多
72 次浏览
要检查 ListDictionary 是否已同步,代码如下:示例 实时演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict = new ListDictionary(); dict.Add("1", "SUV"); dict.Add("2", "Sedan"); dict.Add("3", "Utility Vehicle"); dict.Add("4", "Compact Car"); dict.Add("5", "SUV"); dict.Add("6", "Sedan"); dict.Add("7", "Utility Vehicle"); dict.Add("8", "Compact Car"); dict.Add("9", "Crossover"); dict.Add("10", "Electric Car"); Console.WriteLine("ListDictionary 元素..."); foreach(DictionaryEntry d ... 阅读更多
82 次浏览
要检查 ListDictionary 是否为只读,代码如下:示例 实时演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ ListDictionary dict1 = new ListDictionary(); dict1.Add("A", "Books"); dict1.Add("B", "Electronics"); dict1.Add("C", "Smart Wearables"); dict1.Add("D", "Pet Supplies"); dict1.Add("E", "Clothing"); dict1.Add("F", "Footwear"); Console.WriteLine("ListDictionary1 元素..."); foreach(DictionaryEntry d in dict1){ Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("ListDictionary1 是否具有..."); 阅读更多
86 次浏览
要从 SortedList 中删除所有元素,代码如下:示例 实时演示using System; using System.Collections; public class Demo { public static void Main(String[] args){ SortedList sortedList = new SortedList(); sortedList.Add("A", "1"); sortedList.Add("B", "2"); sortedList.Add("C", "3"); sortedList.Add("D", "4"); sortedList.Add("E", "5"); sortedList.Add("F", "6"); sortedList.Add("G", "7"); sortedList.Add("H", "8"); sortedList.Add("I", "9"); sortedList.Add("J", "10"); Console.WriteLine("SortedList 元素..."); foreach(DictionaryEntry d in sortedList){ ... 阅读更多
144 次浏览
要从 HashSet 中删除所有元素,代码如下:示例 实时演示using System; using System.Collections.Generic; public class Demo { public static void Main(String[] args){ HashSet set1 = new HashSet(); set1.Add("A"); set1.Add("B"); set1.Add("C"); set1.Add("D"); set1.Add("E"); set1.Add("F"); set1.Add("G"); set1.Add("H"); Console.WriteLine("HashSet1 中的元素..."); foreach (string res in set1){ Console.WriteLine(res); } HashSet set2 = new HashSet(); ... 阅读更多
116 次浏览
要获取 OrderedDictionary 的只读副本,代码如下:示例 实时演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ OrderedDictionary dict1 = new OrderedDictionary(); dict1.Add("A", "Books"); dict1.Add("B", "Electronics"); dict1.Add("C", "Smart Wearables"); dict1.Add("D", "Pet Supplies"); dict1.Add("E", "Clothing"); dict1.Add("F", "Footwear"); Console.WriteLine("OrderedDictionary1 元素..."); foreach(DictionaryEntry d in dict1){ Console.WriteLine(d.Key + " " + d.Value); } OrderedDictionary dict2 ... 阅读更多
111 次浏览
要检查两个 Tuple 对象是否相等,代码如下:示例 实时演示using System; public class Demo { public static void Main(String[] args){ var tuple1 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500); var tuple2 = Tuple.Create(150, 400, 500, 700, 100, 1200, 1500); Console.WriteLine("Tuple1 是否等于 Tuple2?= "+tuple1.Equals(tuple2)); } }输出这将产生以下输出:Tuple1 是否等于 Tuple2?= True示例让我们看看另一个示例: 实时演示using System; public class Demo { public static void Main(String[] args){ var tuple1 = ... 阅读更多
111 次浏览
要检查两个 StringBuilder 对象是否相等,代码如下:示例 实时演示using System; using System.Text; public class Demo { public static void Main(String[] args){ StringBuilder strBuilder1 = new StringBuilder("Tim"); StringBuilder strBuilder2 = new StringBuilder("Tom"); StringBuilder strBuilder3 = new StringBuilder(); strBuilder2 = strBuilder3; Console.WriteLine("StringBuilder3 是否等于 StringBuilder2?= "+strBuilder3.Equals(strBuilder2)); } }输出这将产生以下输出:StringBuilder3 是否等于 StringBuilder2?= True示例让我们看看另一个示例: 实时演示using System; using System.Text; public class Demo { public static void ... 阅读更多
148 次浏览
要检查两个 String 对象是否具有相同的值,代码如下:示例 实时演示using System; public class Demo { public static void Main(String[] args){ string str1 = "John"; string str2 = "John"; Console.WriteLine("字符串 1 = "+str1); Console.WriteLine("字符串 2 = "+str2); Console.WriteLine("字符串 1 等于字符串 2:{0}", str1.Equals(str2)); } }输出这将产生以下输出:字符串 1 = John 字符串 2 = John 字符串 1 等于字符串 2:True示例让我们看看另一个示例: 实时演示using System; public ... 阅读更多
138 次浏览
要为 ArrayList 创建一个只读包装器,代码如下 -示例 现场演示使用 System;使用 System.Collections;public class Demo { public static void Main(){ ArrayList list = new ArrayList(); list.Add("One"); list.Add("Two"); list.Add("Three"); list.Add("Four"); list.Add("Five"); list.Add("Six"); list.Add("Seven"); list.Add("Eight"); Console.WriteLine("ArrayList 元素..."); foreach(string str in list){ Console.WriteLine(str); } Console.WriteLine("ArrayList 是否为只读? = "+list.IsReadOnly); } }输出这将产生... 阅读更多