找到 2628 篇文章 关于 C#
92 次浏览
要获取值类型 UInt32 的 TypeCode,代码如下:示例实时演示使用 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示例让我们看另一个示例:实时演示使用 System; public class Demo { ... 阅读更多
428 次浏览
要获取当前类型实现或继承的所有接口,代码如下:示例实时演示使用 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]让我们看另一个示例:示例实时 ... 阅读更多
87 次浏览
要获取当前类型实现或继承的特定接口,代码如下:示例实时演示使用 System; public class Demo { public static void Main() { Type type = typeof(double); Type myInterface = type.GetInterface("IFormattable"); Console.WriteLine("接口 = " + myInterface); } }输出这将产生以下输出:接口 = System.IFormattable示例让我们看另一个示例:实时演示使用 System; public class Demo { public static void Main() { Type type = typeof(float); Type myInterface = type.GetInterface("IFormattable",true); Console.WriteLine("接口 = " + myInterface); } }输出这将产生以下输出:接口 = System.IFormattable
102 次浏览
要获取值类型 UInt64 的 TypeCode,代码如下:示例实时演示使用 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示例让我们看另一个示例:使用 System; public class Demo { public ... 阅读更多
370 次浏览
要检查 Dictionary 是否包含特定值,代码如下:示例实时演示使用 System; using System.Collections.Generic; public class Demo { public static void Main() { Dictionary dict = new Dictionary(); 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 res in dict) { Console.WriteLine("键 = {0},值 = {1}", res.Key, res.Value); ... 阅读更多
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 ... 阅读更多
145 次浏览
要反转整个 ArrayList 中元素的顺序,代码如下:示例实时演示使用 System; using System.Collections; public class Demo { public static void Main(String[] args) { ArrayList list1 = new ArrayList(); list1.Add("A"); list1.Add("B"); list1.Add("C"); list1.Add("D"); list1.Add("E"); list1.Add("F"); list1.Add("G"); list1.Add("H"); list1.Add("I"); Console.WriteLine("ArrayList1 中的元素..."); foreach (string res in list1) { Console.WriteLine(res); } ... 阅读更多
70 次浏览
要将 BitArray 中的所有位设置为指定值,代码如下:示例实时演示使用 System; using System.Collections; public class Demo { public static void Main() { BitArray arr = new BitArray(5); arr[0] = false; arr[1] = false; arr[2] = false; arr[3] = false; Console.WriteLine("BitArray..."); foreach(Object ob in arr) { Console.WriteLine(ob); } arr.SetAll(true); Console.WriteLine("更新后的 BitArray..."); foreach(Object ob in arr) ... 阅读更多
216 次浏览
C# 中的 Byte 结构表示一个 8 位无符号整数。以下是字段:序号字段和描述1MaxValue表示 Byte 的最大可能值。此字段是常量。2MinValue表示 Byte 的最小可能值。此字段是常量。以下是其中一些方法:序号字段和描述1CompareTo(Byte)将此实例与指定的 8 位无符号整数进行比较,并返回其相对值的指示。2CompareTo(Object)将此实例与指定的对象进行比较,并返回其相对值的指示。3Equals(Byte)返回一个值,指示此实例和指定的 Byte 对象是否表示相同的值。4Equals(Object)返回一个值,指示此实例是否等于 ... 阅读更多
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP