找到 34423 篇文章 关于编程
588 次浏览
要检查 HashSet 是否包含指定元素,代码如下所示 -示例 实时演示使用 System;使用 System.Collections.Generic;公共类演示 { 公共静态无效 Main() { HashSet set1 = 新 HashSet(); set1.Add(25); set1.Add(50); set1.Add(75); set1.Add(100); set1.Add(125); set1.Add(150); Console.WriteLine("HashSet1 中的元素"); 针对每个 (int val in set1) { Console.WriteLine(val); } HashSet set2 = 新 HashSet(); set2.Add(30); ... 阅读更多
142 次浏览
要检查数组是否为只读,请尝试以下代码 -示例 实时演示使用 System;公共类演示 { 公共静态无效 Main() { string[] products = 新 string[] { }; Console.WriteLine("一个或多个行星以 'E' 开头?= {0}", Array.Exists(products, ele => ele.StartsWith("E"))); Console.WriteLine("数组是否具有固定大小?= " + products.IsFixedSize); Console.WriteLine("数组是否为只读?= " + products.IsReadOnly); } }输出这将生成以下代码 -一个或多个行星以 'E' 开头?= False 数组是否... 阅读更多
426 次浏览
要获取一个迭代器,用于遍历 Dictionary,代码如下所示 -示例 实时演示使用 System;使用 System.Collections;使用 System.Collections.Generic;公共类演示 { 公共静态无效 Main() { Dictionary dict = 新 Dictionary(); dict.Add(100,"Laptop"); dict.Add(150,"Desktop"); dict.Add(200,"Earphone"); dict.Add(300,"Tablet"); dict.Add(500,"Speakers"); dict.Add(750,"HardDisk"); dict.Add(1000,"SSD"); IDictionaryEnumerator demoEnum = dict.GetEnumerator(); Console.WriteLine("迭代器迭代键值对..."); 当 (demoEnum.MoveNext()) Console.WriteLine("Key = " + demoEnum.Key ... 阅读更多
115 次浏览
要获取一个迭代器,用于遍历 StringCollection,代码如下所示 -示例 实时演示使用 System;使用 System.Collections.Specialized;公共类演示 { 公共静态无效 Main() { StringCollection stringCol = 新 StringCollection(); String[] arr = 新 String[] { "100","200","300","400","500" }; Console.WriteLine("数组元素..."); 针对每个 (string res in arr) { Console.WriteLine(res); } stringCol.AddRange(arr); Console.WriteLine("指定的字符串是否在 StringCollection 中?= " + stringCol.Contains("800")); Console.WriteLine("元素总数 = " + stringCol.Count); ... 阅读更多
148 次浏览
要从 LinkedList 中删除所有节点,代码如下所示 -示例 实时演示使用 System;使用 System.Collections.Generic;公共类演示 { 公共静态无效 Main() { int[] num = {10,20,30,40,50}; LinkedList list = 新 LinkedList(num); Console.WriteLine("LinkedList 节点..."); 针对每个 (var n in list) { Console.WriteLine(n); } list.Clear(); Console.WriteLine("LinkedList 现在为空!"); 针对每个 (var n in list) { Console.WriteLine(n); } } ... 阅读更多
65 次浏览
要从 StringDictionary 中删除所有条目,代码如下所示 -示例 实时演示使用 System;使用 System.Collections;使用 System.Collections.Specialized;公共类演示 { 公共静态无效 Main() { StringDictionary strDict1 = 新 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 元素..."); 针对每个 (DictionaryEntry d in strDict1) { Console.WriteLine(d.Key + " " + d.Value); } ... 阅读更多
93 次浏览
要检查数组是否具有固定大小,请尝试以下代码 -示例 实时演示使用 System;公共类演示 { 公共静态无效 Main() { string[] products = 新 string[] { "Electronics","Accessories","Clothing","Toys","Clothing","Furniture" }; Console.WriteLine("产品列表..."); 针对每个 (string s in products) { Console.WriteLine(s); } Console.WriteLine("数组中是否包含产品 Accessories?= {0}", Array.Exists(products, ele => ele == "Accessories")); Console.WriteLine("数组中是否包含产品 Stationery?= {0}", ... 阅读更多
389 次浏览
要检查数组是否包含满足特定条件的元素,我们可以在 C# 中使用 StartsWith() 方法 -示例 实时演示使用 System;公共类演示 { 公共静态无效 Main() { string[] products = { "Electronics","Accessories","Clothing","Toys","Clothing","Furniture" }; Console.WriteLine("产品列表..."); 针对每个 (string s in products) { Console.WriteLine(s); } Console.WriteLine("一个或多个产品以字母 'C' 开头?= {0}", Array.Exists(products, ele => ele.StartsWith("C"))); Console.WriteLine("一个或多个行星以 'D' 开头?= ... 阅读更多
76 次浏览
要检查 LinkedList 中是否存在值,请尝试以下代码 -示例 实时演示使用 System;使用 System.Collections.Generic;公共类演示 { 公共静态无效 Main() { LinkedList linkedList = 新 LinkedList(); linkedList.AddLast(25); linkedList.AddLast(50); linkedList.AddLast(100); linkedList.AddLast(200); linkedList.AddLast(400); linkedList.AddLast(500); linkedList.AddLast(550); linkedList.AddLast(600); linkedList.AddLast(800); linkedList.AddLast(1200); Console.WriteLine("节点数量 = " + linkedList.Count); 针对每个 (int val in linkedList) { Console.WriteLine(val); } ... 阅读更多
85 次浏览
要检查 HashSet 和指定集合是否共享公共元素,C# 代码如下所示 -示例 实时演示使用 System;使用 System.Collections.Generic;公共类演示 { 公共静态无效 Main() { HashSet set1 = 新 HashSet(); set1.Add(25); set1.Add(50); set1.Add(75); set1.Add(100); set1.Add(125); set1.Add(150); Console.WriteLine("HashSet1 中的元素"); 针对每个 (int val in set1) { Console.WriteLine(val); } HashSet set2 = 新 HashSet(); set2.Add(30); ... 阅读更多
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP