找到关于编程的34423 篇文章

获取当前 C# Decimal 实例的哈希码

AmitDiwan
更新于 2019年12月9日 06:11:04

122 次浏览

要获取当前 Decimal 实例的哈希码,代码如下:示例 在线演示using System; public class Demo {    public static void Main(){       Decimal val = 135269.38193M;       Console.WriteLine("Decimal 值 = {0}", val);       Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );    } }输出这将产生以下输出:Decimal 值 = 135269.38193 HashCode = 1328665595示例让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main(){       Decimal val = Decimal.MaxValue;       Console.WriteLine("Decimal 值 = {0}", val);       Console.WriteLine("HashCode = {0}", (val.GetHashCode()) );    } }输出这将产生以下输出:Decimal 值 = 79228162514264337593543950335 HashCode = 1173356544

将 C# 中逻辑值的指定字符串表示形式转换为其布尔等效项

AmitDiwan
更新于 2019年12月9日 06:08:28

87 次浏览

要将逻辑值的指定字符串表示形式转换为其布尔等效项,代码如下:示例 在线演示using System; public class Demo {    public static void Main(){       bool val;       bool flag;       val = Boolean.TryParse("true", out flag);       Console.WriteLine("Result = "+val);    } }输出这将产生以下输出:示例 在线演示using System; public class Demo {    public static void Main() {       bool val; bool flag;       val = Boolean.TryParse("$", out flag);       Console.WriteLine("Result = "+val);    } }输出这将产生以下输出:Result = False

将当前 C# DateTime 对象的值转换为 UTC

AmitDiwan
更新于 2019年12月9日 06:03:43

2K+ 次浏览

要将当前 DateTime 对象的值转换为协调世界时 (UTC),代码如下:示例 在线演示using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 12, 11, 7, 11, 25);       Console.WriteLine("Date = {0}", d);       DateTime res = d.ToUniversalTime();       Console.WriteLine("String representation = {0}", res);    } }输出这将产生以下输出:Date = 2019/11/11 7:11:25 AM String representation = 2019/11/11 7:11:25 AM示例让我们来看另一个示例: 在线演示using System; public class Demo {    public ... 阅读更多

C# 中列表的容量

AmitDiwan
更新于 2019年12月9日 05:59:30

284 次浏览

要获取列表的容量,代码如下:示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(String[] args){       List list1 = new List();       list1.Add("One");       list1.Add("Two");       list1.Add("Three");       list1.Add("Four");       list1.Add("Five");       Console.WriteLine("List1 中的元素...");       foreach (string res in list1){          Console.WriteLine(res);       }       Console.WriteLine("List1 的容量 = "+list1.Capacity);       List list2 = new List();       list2.Add("India");     ... 阅读更多

C# 中两个 HashSet 的并集

AmitDiwan
更新于 2019年12月9日 05:29:16

198 次浏览

让我们来看一个获取两个 HashSet 并集的示例示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       HashSet set1 = new HashSet();       set1.Add(100);       set1.Add(200);       set1.Add(300);       set1.Add(400);       set1.Add(500);       set1.Add(600);       Console.WriteLine("HashSet1 元素...");       foreach(int ele in set1){          Console.WriteLine(ele);       }       HashSet set2 = new HashSet();       set2.Add(100);       set2.Add(200);       set2.Add(300);     ... 阅读更多

检查 C# 中 HashSet 和指定集合是否包含相同的元素

AmitDiwan
更新于 2019年12月6日 12:42:14

104 次浏览

要检查 HashSet 和指定集合是否包含相同的元素,代码如下:示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main() {       HashSet set1 = new HashSet();       set1.Add("One");       set1.Add("Two");       set1.Add("Three");       set1.Add("Four");       set1.Add("Five");       set1.Add("Six");       set1.Add("Seven");       HashSet set2 = new HashSet();       set2.Add("One");       set2.Add("Two");       set2.Add("Three");       set2.Add("Four");       Console.WriteLine("是否包含相同的 ... 阅读更多

获取 C# 中 OrderedDictionary 中包含键的 ICollection

AmitDiwan
更新于 2019年12月6日 12:40:43

111 次浏览

要获取包含 OrderedDictionary 中键的 ICollection,代码如下:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       OrderedDictionary dict = new OrderedDictionary();       dict.Add("1", "One");       dict.Add("2", "Two");       dict.Add("3", "Three");       dict.Add("4", "Four");       dict.Add("5", "Five");       dict.Add("6", "Six");       dict.Add("7", "Seven");       dict.Add("8", "Eight");       ICollection col = dict.Keys;       String[] strKeys = new String[dict.Count];       col.CopyTo(strKeys, 0);     ... 阅读更多

Java 中的 lambda 表达式是对象吗?

raja
更新于 2020年7月10日 11:04:59

2K+ 次浏览

是的,任何 lambda 表达式在 Java 中都是一个对象。它是函数式接口的一个实例。我们将 lambda 表达式分配给任何变量,并像任何其他对象一样传递它。语法(参数) -> 表达式              或 (参数) -> { 语句; }在下面的示例中,lambda 表达式如何分配给变量以及如何调用它。示例@FunctionalInterface interface ComparatorTask {    public boolean compare(int t1, int t2); } public class LambdaObjectTest {    public static void main(String[] args) {       ComparatorTask ctask = (int t1, int t2) -> {return t1 ... 阅读更多

获取当前 C# 枚举类型的基础类型

AmitDiwan
更新于 2019年12月6日 12:36:43

152 次浏览

要返回当前枚举类型的基础类型,代码如下:示例 在线演示使用 System; public class Demo {    enum Vehicle {Car, Bus, Bike, Airplane}    public static void Main() {       try {          Vehicle v = Vehicle.Bike;          Type type = v.GetType();          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() 返回常量名称 = " + str);          Type type2 = type.GetEnumUnderlyingType();          Console.Write("枚举基础类型 = "+type2);          Console.WriteLine("列表 ... 阅读更多

在 C# 中获取当前枚举类型的成员名称

AmitDiwan
更新于 2019-12-06 12:33:51

43 次查看

要获取当前枚举类型的成员名称,代码如下:示例 在线演示使用 System; public class Demo {    enum Vehicle {Car, Bus, Bike}    public static void Main() {       try {          Type type = typeof(string);          string[] str = type.GetEnumNames();          Console.WriteLine("GetEnumName() 返回常量名称 = " + str);          Console.WriteLine("列出常量 ..");          for (int i = 0; i < str.Length; i++)          Console.Write("{0} ", str[i]);     ... 阅读更多

广告
© . All rights reserved.