找到 2628 篇文章 关于 C#
120 次浏览
要检查指定的 Unicode 字符是否为字母或十进制数字,代码如下所示:示例 在线演示using System; public class Demo { public static void Main() { bool res; char val = '1'; Console.WriteLine("Value = "+val); res = Char.IsLetterOrDigit(val); Console.WriteLine("Is the value a letter or digit? = "+res); } }输出这将产生以下输出:Value = 1 Is the value a letter or digit? = True示例让我们看看另一个示例: 在线演示using System; public class Demo { public static void Main() { bool res; ... 阅读更多
105 次浏览
要获取值类型 Char 的 TypeCode,代码如下所示:示例 在线演示using System; public class Demo { public static void Main() { char val = '5'; bool res; Console.WriteLine("Hashcode for val = "+val.GetHashCode()); res = val.Equals('m'); Console.WriteLine("Return Value = "+res); Console.WriteLine("Numeric Value = "+Char.GetNumericValue(val)); TypeCode type = val.GetTypeCode(); Console.WriteLine("Type = "+type); } }输出这将产生以下输出:Hashcode for val = 3473461 Return Value = False Numeric Value = 5 Type = Char示例让我们看看另一个示例: 在线演示using System; public class ... 阅读更多
114 次浏览
要从 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 elements..."); foreach(DictionaryEntry d in sortedList) ... 阅读更多
70 次浏览
要从 StringDictionary 中移除指定键的条目,代码如下所示:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict1 = new StringDictionary(); strDict1.Add("A", "John"); strDict1.Add("B", "Andy"); strDict1.Add("C", "Tim"); strDict1.Add("D", "Ryan"); strDict1.Add("E", "Kevin"); strDict1.Add("F", "Katie"); strDict1.Add("G", "Brad"); Console.WriteLine("StringDictionary1 key-value pairs..."); foreach(DictionaryEntry de in strDict1) { Console.WriteLine(de.Key + " " + de.Value); ... 阅读更多
117 次浏览
要从 C# 中的 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 elements..."); foreach(DictionaryEntry d in dict) { Console.WriteLine(d.Key + " " + d.Value); } ... 阅读更多
102 次浏览
要获取队列开头的对象,代码如下所示:示例 在线演示using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue queue = new Queue(); queue.Enqueue("A"); queue.Enqueue("B"); queue.Enqueue("C"); queue.Enqueue("D"); queue.Enqueue("E"); queue.Enqueue("F"); queue.Enqueue("G"); Console.WriteLine("Count of elements = "+queue.Count); Console.WriteLine("Element at the beginning of queue = " + queue.Peek()); } }输出这将产生以下输出:Count of elements = 7 Element at the beginning of queue = A示例让我们看看另一个 ... 阅读更多
86 次浏览
要获取或设置与 SortedList 中指定键关联的值,代码如下所示:示例 在线演示using System; using System.Collections; public class Demo { public static void Main() { SortedList list = new SortedList (); list.Add("A", "Books"); list.Add("B", "Electronics"); list.Add("C", "Appliances"); list.Add("D", "Pet Supplies"); list.Add("E", "Clothing"); list.Add("F", "Footwear"); Console.WriteLine("Value associated with key E = "+list["E"]); list["E"] = "HDD"; Console.WriteLine("Value associated with key E [Updated] = "+list["E"]); ... 阅读更多
107 次浏览
要检查两个 StringDictionary 对象是否相等,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringDictionary strDict1 = new StringDictionary(); strDict1.Add("A", "John"); strDict1.Add("B", "Andy"); strDict1.Add("C", "Tim"); strDict1.Add("D", "Ryan"); strDict1.Add("E", "Kevin"); strDict1.Add("F", "Katie"); strDict1.Add("G", "Brad"); StringDictionary strDict2 = new StringDictionary(); strDict2.Add("A", "John"); strDict2.Add("B", "Andy"); strDict2.Add("C", "Tim"); strDict2.Add("D", ... 阅读更多
86 次浏览
要检查两个 StringCollection 对象是否相等,代码如下所示:示例 在线演示using System; using System.Collections.Specialized; public class Demo { public static void Main() { StringCollection strCol1 = new StringCollection(); strCol1.Add("Accessories"); strCol1.Add("Books"); strCol1.Add("Electronics"); Console.WriteLine("StringCollection1 elements..."); foreach (string res in strCol1) { Console.WriteLine(res); } StringCollection strCol2 = new StringCollection(); strCol2.Add("Accessories"); strCol2.Add("Books"); strCol2.Add("Electronics"); Console.WriteLine("StringCollection2 elements..."); foreach ... 阅读更多
93 次浏览
要获取或设置与ListDictionary中指定键关联的值,代码如下所示:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { ListDictionary dict = new ListDictionary(); dict.Add("A", "Books"); dict.Add("B", "Electronics"); dict.Add("C", "Appliances"); dict.Add("D", "Pet Supplies"); dict.Add("E", "Clothing"); dict.Add("F", "Footwear"); Console.WriteLine("Value associated with key C = "+dict["C"]); } }输出这将产生以下输出:与键C关联的值 = Appliances示例让我们看另一个例子: 在线演示using System; using ... 阅读更多