找到 34423 篇文章,关于编程

检查 C# 中的栈是否包含某个元素

AmitDiwan
更新于 2019年12月4日 07:16:10

206 次查看

要检查栈是否包含元素,请使用 C# 的 Contains() 方法。以下为代码 -示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Stack stack = new Stack();       stack.Push(100);       stack.Push(150);       stack.Push(175);       stack.Push(200);       stack.Push(225);       stack.Push(250);       stack.Push(300);       stack.Push(400);       stack.Push(450);       stack.Push(500);       Console.WriteLine("栈中的元素:");       foreach(var val in stack){          Console.WriteLine(val);       ... 阅读更多

如何在 Java 中将 lambda 表达式与函数式接口一起使用?

raja
更新于 2020年7月10日 06:24:13

687 次查看

lambda 表达式是匿名函数,没有返回值类型、访问修饰符,也不属于任何类。它可以用来简化函数式接口中抽象方法的实现。只要有函数式接口,我们就可以使用 lambda 表达式来代替匿名内部类。语法([逗号分隔的参数列表]) -> {主体}示例@FunctionalInterface interface BonusCalculator {    public double calcBonus(int amount); } class EmpDetails {    public void getBonus(BonusCalculator calculator, int amount) {       double bonus = calculator.calcBonus(amount);       System.out.println("奖金: " + bonus);    } } public class LambdaExpressionTest {    public static void main(String[] ... 阅读更多

检查 C# 中的 SortedSet 对象是否为指定集合的真超集

AmitDiwan
更新于 2019年12月4日 07:12:05

89 次查看

要检查 SortedSet 对象是否为指定集合的真超集,代码如下所示 -示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add(10);       set1.Add(20);       set1.Add(30);       set1.Add(40);       set1.Add(50);       set1.Add(60);       Console.WriteLine("SortedSet1 中的元素...");       foreach (int res in set1){          Console.WriteLine(res);       }       SortedSet set2 = new SortedSet();       ... 阅读更多

检查 C# 中的 SortedSet 对象是否为指定集合的真子集

AmitDiwan
更新于 2019年12月4日 07:03:39

58 次查看

要检查 SortedSet 对象是否为指定集合的真子集,代码如下所示 -示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       SortedSet set1 = new SortedSet();       set1.Add(20);       set1.Add(40);       set1.Add(60);       set1.Add(80);       set1.Add(100);       set1.Add(120);       set1.Add(140);       Console.WriteLine("SortedSet1 中的元素...");       foreach (int res in set1){          Console.WriteLine(res);       }       SortedSet set2 = new SortedSet(); ... 阅读更多

检查 C# 中的哈希表是否包含特定值

AmitDiwan
更新于 2019年12月4日 06:59:53

162 次查看

要检查哈希表是否包含特定值,代码如下所示 -示例 实时演示using System; using System.Collections; public class Demo {    public static void Main(){       Hashtable hash = new Hashtable();       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("哈希表键值对...");       foreach(DictionaryEntry entry in ... 阅读更多

检查 C# 中的哈希表是否具有固定大小

AmitDiwan
更新于 2019年12月4日 06:54:47

111 次查看

要检查哈希表是否具有固定大小,代码如下所示 -示例 实时演示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("哈希表是否具有固定大小?= "+hash.IsFixedSize);    } }输出这将 ... 阅读更多

检查 C# 中的队列是否包含某个元素

AmitDiwan
更新于 2019年12月4日 06:43:34

158 次查看

要检查队列是否包含某个元素,代码如下所示 -示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Queue queue = new Queue();       queue.Enqueue("电子产品");       queue.Enqueue("配件");       queue.Enqueue("玩具");       queue.Enqueue("书籍");       queue.Enqueue("家具");       queue.Enqueue("服装");       queue.Enqueue("鞋类");       queue.Enqueue("厨具");       queue.Enqueue("宠物用品");       Console.WriteLine("队列中的元素...");       foreach(var element in queue){          Console.WriteLine(element);       }       Console.WriteLine("是否 ... 阅读更多

检查 C# 中的集合是否包含某个元素

AmitDiwan
更新于 2019年12月4日 06:39:03

117 次查看

要检查集合是否包含某个元素,代码如下所示 -示例 实时演示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# 中的数组对象是否等于另一个数组对象

AmitDiwan
更新于 2019年12月4日 06:35:35

214 次查看

要检查数组对象是否等于另一个数组对象,代码如下所示 -示例 实时演示using System; public class Demo {    public static void Main(){       String[] strArr1 = new String[3] { "John", "Jacob", "Tim"};       String[] strArr2 = new String[3] { "Tom", "Brad", "Bradley"};       Console.WriteLine("第一个字符串数组...");       foreach(string val in strArr1){          Console.WriteLine(val);       }       Console.WriteLine("第二个字符串数组...");       foreach(string val in strArr2){          Console.WriteLine(val);       }       ... 阅读更多

在 C# 中检查 HashSet 是否是指定集合的真子集

AmitDiwan
更新于 2019年12月4日 06:31:17

88 次浏览

要检查 HashSet 是否是指定集合的真子集,请尝试以下代码 -示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       HashSet set1 = new HashSet();       set1.Add(70);       set1.Add(100);       set1.Add(125);       set1.Add(150);       Console.WriteLine("HashSet1 中的元素");       foreach(int val in set1){          Console.WriteLine(val);       }       HashSet set2 = new HashSet();       set2.Add(30);       set2.Add(60);       set2.Add(70);       ... 阅读更多

广告

© . All rights reserved.