找到 34423 篇文章 关于编程

获取C#中字典中键值对的数量

AmitDiwan
更新于 2019年12月11日 07:24:04

474 次浏览

要获取字典中键值对的数量,代码如下:示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       Dictionary<string, string> dict =       new Dictionary<string, string>();       dict.Add("One", "Chris");       dict.Add("Two", "Steve");       dict.Add("Three", "Messi");       dict.Add("Four", "Ryan");       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#中将64位有符号整数重新解释为双精度浮点数

AmitDiwan
更新于 2019年12月11日 07:22:35

397 次浏览

要将指定的64位有符号整数重新解释为双精度浮点数,代码如下:示例 在线演示using System; public class Demo {    public static void Main() {       long d = 9846587687;       Console.Write("值 (64位有符号整数) = "+d);       double res = BitConverter.Int64BitsToDouble(d);       Console.Write("值 (双精度浮点数) = "+res);    } }输出这将产生以下输出:值 (64位有符号整数) = 9846587687 值 (双精度浮点数) = 4.86486070491012E-314示例让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main() {       long d = 20;     ... 阅读更多

在C#中将指定字符串的值转换为其等效的Unicode字符

AmitDiwan
更新于 2019年12月11日 07:21:24

292 次浏览

要将指定字符串的值转换为其等效的Unicode字符,代码如下:示例 在线演示using System; public class Demo {    public static void Main(){       bool res;       Char ch;       res = Char.TryParse("10", out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }输出这将产生以下输出:False示例让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main(){       bool res;       Char ch;       res = Char.TryParse("P", out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }输出这将产生以下输出:True P

在C#中将指定的双精度浮点数转换为64位有符号整数

AmitDiwan
更新于 2019年12月11日 07:20:20

319 次浏览

要将指定的双精度浮点数转换为64位有符号整数,代码如下:示例 在线演示using System; public class Demo {    public static void Main() {       double d = 5.646587687;       Console.Write("值 = "+d);       long res = BitConverter.DoubleToInt64Bits(d);       Console.Write("64位有符号整数 = "+res);    } }输出这将产生以下输出:值 = 5.646587687 64位有符号整数 = 4618043510978159912示例让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main() {       double d = 0.001;       Console.Write("值 = "+d);     ... 阅读更多

C#中的异常

AmitDiwan
更新于 2019年12月11日 07:19:13

287 次浏览

异常是在程序执行期间出现的错误。C#异常是对程序运行期间出现的异常情况的响应,例如尝试除以零。异常提供了一种将控制从程序的一个部分转移到另一个部分的方法。C#异常处理建立在四个关键字之上:try – try块标识一个激活特定异常的代码块。它后面跟着一个或多个catch块。catch – 程序用异常处理程序在程序中的某个地方捕获异常。… 阅读更多

在C#中将当前DateTime对象的数值转换为Windows文件时间

AmitDiwan
更新于 2019年12月11日 07:17:06

219 次浏览

要将当前DateTime对象的数值转换为Windows文件时间,代码如下:示例 在线演示using System; public class Demo {    public static void Main() {       DateTime d = DateTime.Now;       Console.WriteLine("日期 = {0}", d);       long res = d.ToFileTime();       Console.WriteLine("Windows文件时间 = {0}", res);    } }输出这将产生以下输出:日期 = 2019/10/16 上午8:17:26 Windows文件时间 = 132156874462559390示例让我们来看另一个示例: 在线演示using System; public class Demo {    public static void Main() {       DateTime d = new DateTime(2019, 05, 10, 6, ... 阅读更多

如何在C#的switch语句中使用字符串

AmitDiwan
更新于 2019年12月11日 07:15:20

2K+ 次浏览

switch语句允许测试变量与值列表的相等性。每个值称为一个case,被切换的变量将针对每个switch case进行检查。示例以下是如何在switch语句中使用字符串的示例: 在线演示using System; public class Demo {    public static void Main(String[] args){       string grades = "A1";       switch (grades) {           case "A1":               Console.WriteLine("非常好!");               break;           case "A2":           ... 阅读更多

获取一个在C#中迭代StringDictionary的枚举器

AmitDiwan
更新于 2019年12月11日 07:13:32

70 次浏览

要获取一个迭代StringDictionary的枚举器,代码如下:示例 在线演示using System; using System.Collections; using System.Collections.Specialized; public class Demo {    public static void Main() {       StringDictionary strDict1 = new StringDictionary();       strDict1.Add("A", "John");       strDict1.Add("B", "Andy");       strDict1.Add("C", "Tim");       strDict1.Add("D", "Ryan");       strDict1.Add("E", "Kevin");       strDict1.Add("F", "Katie");       strDict1.Add("G", "Brad");       Console.WriteLine("StringDictionary1 元素...");       foreach(DictionaryEntry de in strDict1) {           Console.WriteLine(de.Key + " " + de.Value);       } ... 阅读更多

C#中的foreach循环

AmitDiwan
更新于 2019年12月11日 07:11:40

409 次浏览

foreach循环为实现System.Collections.IEnumerable或System.Collections.Generic.IEnumerable接口的类型的每个实例中的每个元素执行语句或语句块。示例让我们来看一个foreach循环的示例: 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main(){       LinkedList<int> linkedList = new LinkedList<int>();       linkedList.AddLast(25);       linkedList.AddLast(50);       linkedList.AddLast(100);       linkedList.AddLast(200);       linkedList.AddLast(400);       linkedList.AddLast(500);       linkedList.AddLast(550);       linkedList.AddLast(600);       linkedList.AddLast(800);       linkedList.AddLast(1200);       Console.WriteLine("计数 ... 阅读更多

获取一个在C#中迭代SortedSet的枚举器

AmitDiwan
更新于 2019年12月11日 07:10:21

浏览量:61

要获取一个迭代遍历SortedSet的枚举器,代码如下所示 - 示例 在线演示using System; using System.Collections.Generic; public class Demo {    public static void Main() {       SortedSet<string> set1 = new SortedSet<string>();       set1.Add("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("SortedSet1 中的元素...");       foreach (string res in set1) {          Console.WriteLine(res);       }       SortedSet<string> set2 = new SortedSet<string>();       set2.Add("BC");       set2.Add("CD");       set2.Add("DE");       ... 阅读更多

广告
© . All rights reserved.