找到 34423 篇文章,关于编程

检查两个 StringCollection 对象在 C# 中是否相等

AmitDiwan
更新于 2019年12月5日 10:48:15

86 次查看

要检查两个 StringCollection 对象是否相等,代码如下所示:示例 实时演示使用 System; 使用 System.Collections.Specialized; 公共类 Demo {    公共静态无效 Main() {       StringCollection strCol1 = 新 StringCollection();       strCol1.Add("配件");       strCol1.Add("书籍");       strCol1.Add("电子产品");       Console.WriteLine("StringCollection1 元素...");       针对 (字符串 res in strCol1) {           Console.WriteLine(res);       }       StringCollection strCol2 = 新 StringCollection();       strCol2.Add("配件");       strCol2.Add("书籍");       strCol2.Add("电子产品");       Console.WriteLine("StringCollection2 元素...");       针对 ... 阅读更多

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

AmitDiwan
更新于 2019年12月5日 10:42:04

93 次查看

要获取或设置与 ListDictionary 中指定键关联的值,代码如下所示:示例 实时演示使用 System; 使用 System.Collections; 使用 System.Collections.Specialized; 公共类 Demo {    公共静态无效 Main() {       ListDictionary dict = 新 ListDictionary();       dict.Add("A", "书籍");       dict.Add("B", "电子产品");       dict.Add("C", "家电");       dict.Add("D", "宠物用品");       dict.Add("E", "服装");       dict.Add("F", "鞋类");       Console.WriteLine("与键 C 关联的值 = " + dict["C"]);    } }输出这将产生以下输出:值 关联 与 键 C = 家电示例让我们看看另一个示例: 实时演示使用 System; 使用 ... 阅读更多

从 C# 中的 SortedSet 中删除与谓词匹配的元素

AmitDiwan
更新于 2019年12月5日 10:38:23

254 次查看

要从与谓词匹配的 SortedSet 中删除元素,代码如下所示:示例 实时演示使用 System; 使用 System.Collections.Generic; 公共类 Demo {    私有静态布尔型 demo(int i) {       返回 ((i % 10) == 0);    }    公共静态无效 Main(String[] args) {       SortedSet set1 = 新 SortedSet();       set1.Add(200);       set1.Add(215);       set1.Add(310);       set1.Add(500);       set1.Add(600);       Console.WriteLine("SortedSet 元素...");       针对 (int i in set1) {           Console.WriteLine(i);       } ... 阅读更多

从 C# 中的 HashSet 中删除由谓词定义的条件的元素

AmitDiwan
更新于 2019年12月5日 10:34:20

253 次查看

要从由谓词定义的条件的 HashSet 中删除元素,代码如下所示:示例 实时演示使用 System; 使用 System.Collections.Generic; 公共类 Demo {    私有静态布尔型 demo(int i) {       返回 (i == 100);    }    公共静态无效 Main(String[] args) {       HashSet list = 新 HashSet();       list.Add(100);       list.Add(300);       list.Add(400);       list.Add(500);       list.Add(600);       Console.WriteLine("HashSet 元素...");       针对 (int i in list) {           Console.WriteLine(i);       } ... 阅读更多

删除 C# 中集合中指定索引处的元素

AmitDiwan
更新于 2019年12月5日 10:26:35

122 次查看

要删除集合中指定索引处的元素,代码如下所示:示例 实时演示使用 System; 使用 System.Collections.ObjectModel; 公共类 Demo {    公共静态无效 Main() {       Collection col = 新 Collection();       col.Add("Andy");       col.Add("Kevin");       col.Add("John");       col.Add("Kevin");       col.Add("Mary");       col.Add("Katie");       col.Add("Barry");       col.Add("Nathan");       col.Add("Mark");       Console.WriteLine("元素计数 = " + col.Count);       Console.WriteLine("遍历集合...");       var enumerator = col.GetEnumerator();       当 (enumerator.MoveNext()) ... 阅读更多

Java 中 lambda 表达式可以有多少个参数?

raja
更新于 2020年7月10日 08:32:24

4K+ 次查看

lambda 表达式简单易懂,包含三个部分:参数(方法参数)、箭头运算符(->)和表达式(方法体)。lambda 表达式可以分为三种类型:无参数 lambda 表达式、单参数 lambda 表达式和多参数 lambda 表达式。无参数 lambda 表达式如果需要创建无参数 lambda 表达式,则以空括号开头表达式。语法() -> {    //无参数 lambda 的主体}示例(无参数 Lambda)导入 java.util.function.*; 导入 java.util.Random; 公共类 LambdaExpression1 {    公共静态无效 main(String args[]) {       NumberUtil num = 新 NumberUtil();       int randVal = num.getRandomValue(       ... 阅读更多

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

AmitDiwan
更新于 2019年12月5日 10:07:08

255 次查看

要获取元组的第二个元素,代码如下所示:示例 实时演示使用 System; 公共类 Demo {    公共静态无效 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# 检查 HybridDictionary 是否为只读

AmitDiwan
更新于 2019年12月5日 09:58:15

55 次查看

要检查 HybridDictionary 是否为只读,代码如下所示 - 示例 演示使用 System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary dict1 = new HybridDictionary(); 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("HybridDictionary1 元素..."); foreach(DictionaryEntry d in dict1) { Console.WriteLine(d.Key + " " + d.Value); } Console.WriteLine("是否 ... 阅读更多

在 C# 中获取包含 HybridDictionary 中键的 ICollection

AmitDiwan
更新于 2019年12月5日 08:09:38

浏览量 59 次

要获取包含 HybridDictionary 中键的 ICollection,代码如下所示 - 示例 演示使用 System; using System.Collections.Specialized; public class Demo { public static void Main(){ HybridDictionary dict = new HybridDictionary(); dict.Add("One", "Katie"); dict.Add("Two", "Andy"); dict.Add("Three", "Gary"); dict.Add("Four", "Mark"); dict.Add("Five", "Marie"); dict.Add("Six", "Sam"); dict.Add("Seven", "Harry"); dict.Add("Eight", "Kevin"); dict.Add("Nine", "Ryan"); String[] strArr = new String[dict.Count]; dict.Keys.CopyTo(strArr, 0); for (int i ... 阅读更多

在 C# 中获取一个迭代遍历 SortedDictionary 的枚举器

AmitDiwan
更新于 2019年12月5日 08:06:48

浏览量 96 次

要获取一个迭代遍历 SortedDictionary 的枚举器,代码如下所示 - 示例 演示使用 System; using System.Collections; using System.Collections.Generic; public class Demo { public static void Main(){ SortedDictionary sortedDict = new SortedDictionary(); sortedDict.Add(100, "Mobile"); sortedDict.Add(200, "Laptop"); sortedDict.Add(300, "Desktop"); sortedDict.Add(400, "Speakers"); sortedDict.Add(500, "Headphone"); sortedDict.Add(600, "Earphone"); Console.WriteLine("SortedDictionary 键值对..."); IDictionaryEnumerator demoEnum = sortedDict.GetEnumerator(); while (demoEnum.MoveNext()) Console.WriteLine("Key = " + demoEnum.Key + ", Value = " + ... 阅读更多

广告
© . All rights reserved.