找到 34423 篇文章,关于编程

从 C# 中的 SortedList 中移除指定键的元素

AmitDiwan
更新于 2019-12-05 12:29:52

184 次浏览

要移除 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 ... 阅读更多

从 C# 中的 ArrayList 中移除指定索引处的元素

AmitDiwan
更新于 2019-12-05 12:26:06

103 次浏览

要移除 ArrayList 中指定索引处的元素,代码如下所示:示例 在线演示 using System; using System.Collections; public class Demo {    public static void Main(String[] args) {       ArrayList list1 = new ArrayList();       list1.Add("A");       list1.Add("B");       list1.Add("C");       list1.Add("D");       list1.Add("E");       list1.Add("F");       list1.Add("G");       list1.Add("H");       list1.Add("I");       Console.WriteLine("ArrayList1 中的元素...");       foreach (string res in list1) {          Console.WriteLine(res);       } ... 阅读更多

获取 C# 中 StringCollection 中字符串的数量

AmitDiwan
更新于 2019-12-05 12:18:59

53 次浏览

要获取 StringCollection 中字符串的数量,代码如下所示:示例 在线演示 using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection strCol = new StringCollection();       String[] strArr = new String[] { "A", "B", "C", "D", "E", "F", "G", "H" };       Console.WriteLine("StringCollection 元素...");       foreach (string str in strArr) {          Console.WriteLine(str);       }       strCol.AddRange(strArr);       Console.WriteLine("第 5 个索引处的元素 = "+strCol[5]);       Console.WriteLine("StringCollection 中字符串的数量 = " ... 阅读更多

在 C# 中的 StringDictionary 中获取或设置与指定键关联的值

AmitDiwan
更新于 2019-12-05 12:14:47

66 次浏览

要获取或设置 StringDictionary 中与指定键关联的值,代码如下所示:示例 在线演示 using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary strDict = new StringDictionary ();       strDict.Add("A", "Books");       strDict.Add("B", "Electronics");       strDict.Add("C", "Appliances");       strDict.Add("D", "Pet Supplies");       strDict.Add("E", "Clothing");       strDict.Add("F", "Footwear");       Console.WriteLine("与键 D 关联的值 = "+strDict["D"]);       Console.WriteLine("与键 F 关联的值 = "+strDict["F"]);    } }输出这将产生以下输出 ... 阅读更多

从 C# 中的 StringCollection 的指定索引处移除

AmitDiwan
更新于 2019-12-05 12:10:53

88 次浏览

要从 StringCollection 的指定索引处移除,代码如下所示:示例 在线演示 using System; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringCollection stringCol = new StringCollection();       String[] arr = new String[] { "100", "200", "300", "400", "500" };       Console.WriteLine("数组元素...");       foreach (string res in arr) {          Console.WriteLine(res);       }       stringCol.AddRange(arr);         Console.WriteLine("元素总数 = "+stringCol.Count);       stringCol.RemoveAt(3);       Console.WriteLine("元素总数 ... 阅读更多

如何在 C# 中获取元组的第七个元素?

AmitDiwan
更新于 2019-12-05 12:06:35

64 次浏览

要获取元组的第七个元素,代码如下所示:示例 在线演示 using System; public class Demo {    public static void Main(String[] args) {       var tuple1 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       var tuple2 = Tuple.Create(75, 200, 500, 700, 100, 1200, 1500);       Console.WriteLine("Tuple1 等于 Tuple2 吗? = "+tuple1.Equals(tuple2));       Console.WriteLine("Tuple1 的哈希码 = "+tuple1.GetHashCode());       Console.WriteLine("Tuple2 的哈希码 = "+tuple2.GetHashCode());       Console.WriteLine("Tuple1 第 1 个项目 = "+tuple1.Item1);       Console.WriteLine("Tuple2 第 1 个项目 = "+tuple2.Item1);       Console.WriteLine("Tuple1 第 2 个项目 ... 阅读更多

从 C# 中的 Hashtable 中移除所有元素

AmitDiwan
更新于 2019-12-05 12:03:24

150 次浏览

要从 Hashtable 中移除所有元素,代码如下所示:示例 在线演示 using System; using System.Collections; public class Demo {    public static void Main() {       Hashtable hash = new Hashtable(10);       hash.Add("1", "A");       hash.Add("2", "B");       hash.Add("3", "C");       hash.Add("4", "D");       hash.Add("5", "E");       hash.Add("6", "F");       hash.Add("7", "G");       hash.Add("8", "H");       hash.Add("9", "I");       hash.Add("10", "J");       Console.WriteLine("Hashtable 键值对...");       foreach(DictionaryEntry entry in hash) ... 阅读更多

从 C# 中的集合中移除所有元素

AmitDiwan
更新于 2019-12-05 11:58:52

331 次浏览

要从集合中移除所有元素,代码如下所示:示例 在线演示 using System; using System.Collections.ObjectModel; public class Demo {    public static void Main() {       Collection col = new Collection();       col.Add(10);       col.Add(20);       col.Add(30);       col.Add(40);       col.Add(50);       col.Add(60);       col.Add(70);       col.Add(80);       Console.WriteLine("集合中的元素...");       foreach(int val in col) {          Console.WriteLine(val);       }       Console.WriteLine("集合是否包含元素 ... 阅读更多

检查 C# 中指定的 Unicode 字符是否为标点符号

AmitDiwan
更新于 2019-12-05 11:53:57

212 次浏览

要检查指定的Unicode字符是否为标点符号,代码如下所示:示例 在线演示使用 System; public class Demo {    public static void Main() {       bool res;       char val = 'q';       Console.WriteLine("Value = "+val);       res = Char.IsPunctuation(val);       Console.WriteLine("Is the value a punctuation? = "+res);    } }输出这将产生以下输出:Value = q Is the value a punctuation? = False示例让我们看另一个例子: 在线演示使用 System; public class Demo {    public static void Main() {     ... 阅读更多

获取当前Int64实例在C#中的哈希码

AmitDiwan
更新于 2019年12月5日 11:51:00

浏览量 107 次

要获取当前Int64实例的哈希码,代码如下所示:示例 在线演示使用 System; public class Demo {    public static void Main() {       long val1 = 8768768768;       long val2 = 7889765555;       Console.WriteLine("Value1 = "+val1);       Console.WriteLine("Value2 = "+val2);       Console.WriteLine("Are they equal? = "+val1.Equals(val2));       Console.WriteLine("Value1 (HashCode) = "+val1.GetHashCode());       Console.WriteLine("Value2 (HashCode) = "+val2.GetHashCode());    } }输出这将产生以下输出:Value1 = 8768768768 Value2 = 7889765555 Are they equal? = False Value1 (HashCode) = 178834178 Value2 (HashCode) = -700169038示例让我们看另一个例子: 在线演示使用 System; public class Demo { ... 阅读更多

广告
© . All rights reserved.