找到 2628 篇文章 关于 C#
129 次浏览
要获取值类型 Decimal 的 TypeCode,代码如下:示例 实时演示using System; public class Demo { public static void Main(){ Decimal val = Decimal.MaxValue; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); TypeCode type = val.GetTypeCode(); Console.WriteLine("TypeCode = "+type); } }输出这将产生以下输出:Decimal Value = 79228162514264337593543950335 HashCode = 1173356544 TypeCode = Decimal示例让我们再看一个示例: 实时演示using System; public class Demo { public static void Main(){ ... 阅读更多
122 次浏览
要获取当前 Decimal 实例的哈希码,代码如下:示例 实时演示using System; public class Demo { public static void Main(){ Decimal val = 135269.38193M; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); } }输出这将产生以下输出:Decimal Value = 135269.38193 HashCode = 1328665595示例让我们再看一个示例: 实时演示using System; public class Demo { public static void Main(){ Decimal val = Decimal.MaxValue; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); } }输出这将产生以下输出:Decimal Value = 79228162514264337593543950335 HashCode = 1173356544
86 次浏览
要将逻辑值的指定字符串表示形式转换为其布尔等效项,代码如下:示例 实时演示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
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 = 11/11/2019 7:11:25 AM String representation = 11/11/2019 7:11:25 AM示例让我们再看一个示例: 实时演示using System; public class Demo { public ... 阅读更多
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("Elements in List1..."); foreach (string res in list1){ Console.WriteLine(res); } Console.WriteLine("Capacity of List1 = "+list1.Capacity); List list2 = new List(); list2.Add("India"); ... 阅读更多
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 elements..."); foreach(int ele in set1){ Console.WriteLine(ele); } HashSet set2 = new HashSet(); set2.Add(100); set2.Add(200); set2.Add(300); ... 阅读更多
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("Does it contains the same ... 阅读更多
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); ... 阅读更多
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("列表 ... 阅读更多
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]); ... 阅读更多