找到 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<int> stack = new Stack<int>();       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<int> set1 = new SortedSet<int>();       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<int> set2 = new SortedSet<int>();       ... 阅读更多

检查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<int> set1 = new SortedSet<int>();       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<int> set2 = new SortedSet<int>(); ... 阅读更多

检查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<string> queue = new Queue<string>();       queue.Enqueue("Electronics");       queue.Enqueue("Accessories");       queue.Enqueue("Toys");       queue.Enqueue("Books");       queue.Enqueue("Furniture");       queue.Enqueue("Clothing");       queue.Enqueue("Footwear");       queue.Enqueue("Cookware");       queue.Enqueue("Pet Supplies");       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<int> col = new Collection<int>();       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.