找到 34423 篇文章,关于编程

在 C# 中在堆栈顶部插入对象

AmitDiwan
更新于 2019-12-11 10:12:29

197 次浏览

要在堆栈顶部插入对象,代码如下:示例 实时演示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);       Console.WriteLine("堆栈中的元素:");       foreach(var val in stack) {          Console.WriteLine(val);       }       Console.WriteLine("堆栈中元素的数量 = "+stack.Count);       ... 阅读更多

在 C# 中在指定索引处将元素插入 ArrayList

AmitDiwan
更新于 2019-12-11 10:08:05

251 次浏览

要在指定索引处将元素插入 ArrayList,代码如下:示例 实时演示using System; using System.Collections; public class Demo {    public static void Main() {       ArrayList list = new ArrayList();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");         Console.WriteLine("ArrayList 元素...");       foreach(string str in list) {          Console.WriteLine(str);       }       Console.WriteLine("ArrayList 是只读的?... 阅读更多

获取 C# 中 UInt32 值类型的 TypeCode

AmitDiwan
更新于 2019-12-11 10:04:29

92 次浏览

要获取 UInt32 值类型的 TypeCode,代码如下:示例 实时演示using System; public class Demo {    public static void Main() {       uint val1 = 55;       uint val2 = 100;       TypeCode type1 = val1.GetTypeCode();       TypeCode type2 = val2.GetTypeCode();       Console.WriteLine("val1 的 Typecode = "+type1);       Console.WriteLine("val2 的 Typecode = "+type2);    } }输出这将产生以下输出:val1 的 Typecode = UInt32 val2 的 Typecode = UInt32示例让我们看看另一个示例: 实时演示using System; public class Demo {   ... 阅读更多

获取 C# 中当前类型实现或继承的所有接口

AmitDiwan
更新于 2019-12-11 10:01:43

428 次浏览

要获取当前类型实现或继承的所有接口,代码如下:示例 实时演示using System; public class Demo {    public static void Main() {       Type type = typeof(float);       Type myInterface = type.GetInterface("IFormattable", true);       Type[] myInterfaces = type.GetInterfaces();       Console.WriteLine("接口 = "+myInterface);       Console.WriteLine("所有接口...");       for (int i = 0; i < myInterfaces.Length; i++)       Console.WriteLine(""+myInterfaces[i]);    } }输出这将产生以下输出:接口 = System.IFormattable 所有接口... System.IComparable System.IFormattable System.IConvertible System.IComparable`1[System.Single] System.IEquatable`1[System.Single]让我们看看另一个示例:示例 实时... 阅读更多

获取 C# 中当前类型实现或继承的特定接口

AmitDiwan
更新于 2019-12-11 09:59:31

87 次浏览

要获取当前类型实现或继承的特定接口,代码如下:示例 实时演示using System; public class Demo {    public static void Main() {       Type type = typeof(double);       Type myInterface = type.GetInterface("IFormattable");       Console.WriteLine("接口 = "+myInterface);    } }输出这将产生以下输出:接口 = System.IFormattable示例让我们看看另一个示例: 实时演示using System; public class Demo {    public static void Main() {       Type type = typeof(float);       Type myInterface = type.GetInterface("IFormattable",true);       Console.WriteLine("接口 = "+myInterface);    } }输出这将产生以下输出:接口 = System.IFormattable

Java 中 lambda 表达式的特点是什么?

raja
更新于 2020-07-10 12:44:50

953 次浏览

lambda 表达式是在 Java 8 中引入的,它促进了函数式编程。lambda 表达式只能与函数式接口很好地配合使用,我们不能将 lambda 表达式与多个抽象方法一起使用。Lambda 表达式的特点可选类型声明 - 无需声明参数的类型。编译器从参数的值中推断出相同的类型。参数周围的可选括号 - 无需在括号中声明单个参数。对于多个参数,需要括号。可选大括号 - 如果表达式体包含一个… 阅读更多

获取 C# 中 UInt64 值类型的 TypeCode

AmitDiwan
更新于 2019-12-11 08:16:17

102 次浏览

要获取 UInt64 值类型的 TypeCode,代码如下:示例 实时演示using System; public class Demo {    public static void Main() {       ulong val1 = 55;       ulong val2 = 100;       TypeCode type1 = val1.GetTypeCode();       TypeCode type2 = val2.GetTypeCode();       Console.WriteLine("val1 的 Typecode = "+type1);       Console.WriteLine("val2 的 Typecode = "+type2);    } }输出这将产生以下输出:val1 的 Typecode = UInt64 val2 的 Typecode = UInt64示例让我们看看另一个示例:using System; public class Demo {    public ... 阅读更多

检查 Dictionary是否包含 C# 中的特定值

AmitDiwan
更新于 2019-12-11 08:13:50

370 次浏览

要检查 Dictionary 是否包含特定值,代码如下:示例 实时演示using System; using System.Collections.Generic; public class Demo {    public static void Main() {       Dictionary<string, string> dict =       new Dictionary<string, string>();       dict.Add("One", "John");       dict.Add("Two", "Tom");       dict.Add("Three", "Jacob");       dict.Add("Four", "Kevin");       dict.Add("Five", "Nathan");       Console.WriteLine("元素的数量 = "+dict.Count);       Console.WriteLine("键/值对...");       foreach(KeyValuePair<string, string> res in dict) {          Console.WriteLine("键 = {0}, 值 = {1}", res.Key, res.Value); ... 阅读更多

C# 中的方法参数

AmitDiwan
更新于 2019-12-11 08:08:00

416 次浏览

参数用于向方法传递和接收数据。让我们首先看看语法:访问说明符 - 这决定了另一个类中变量或方法的可见性。返回类型 - 方法可能会返回值。返回类型是方法返回值的数据类型。如果方法不返回任何值,则返回类型为 void。方法名 - 方法名是唯一的标识符,并且区分大小写。它不能与类中声明的任何其他标识符相同。参数列表 - 参数列表包含在括号中,... 阅读更多

反转 C# 中整个列表或指定范围内的元素顺序

AmitDiwan
更新于 2019-12-11 08:05:55

223 次浏览

要反转整个列表中元素的顺序,代码如下所示 - 示例 在线演示使用 System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args) {       List list = new List();       list.Add("One");       list.Add("Two");       list.Add("Three");       list.Add("Four");       list.Add("Five");       list.Add("Six");       list.Add("Seven");       list.Add("Eight");       Console.WriteLine("枚举器遍历列表元素...");       List.Enumerator demoEnum = list.GetEnumerator();       while (demoEnum.MoveNext()) {          string res ... 阅读更多

广告
© . All rights reserved.