找到 34423 篇文章 编程

获取 C# 中 Dictionary 中键值对的数量

AmitDiwan
更新于 2019-12-11 07:24:04

474 次浏览

要获取 Dictionary 中键值对的数量,代码如下:示例 实时演示使用 System;使用 System.Collections.Generic;公共类演示{    公共静态无效 Main(){       字典 dict =       新字典();       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("键值对...");       针对(键值对 res 在 dict 中){          Console.WriteLine("键 = {0},值 = {1}",res.Key,res.Value);       ... 阅读更多

在 C# 中将 64 位有符号整数重新解释为双精度浮点数

AmitDiwan
更新于 2019-12-11 07:22:35

397 次浏览

要将指定的 64 位有符号整数重新解释为双精度浮点数,代码如下:示例 实时演示使用 System;公共类演示{    公共静态无效 Main() {       长 d = 9846587687;       Console.Write("值(64 位有符号整数)= " + d);       双精度 res = BitConverter.Int64BitsToDouble(d);       Console.Write("值(双精度浮点数)= " + res);    } }输出这将产生以下输出:值 (64 位 有符号 整数) = 9846587687 值 (双精度 浮点数) = 4.86486070491012E-314示例让我们看另一个示例: 实时演示使用 System;公共类演示{    公共静态无效 Main() {       长 d = 20;     ... 阅读更多

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

AmitDiwan
更新于 2019-12-11 07:21:24

292 次浏览

要将指定字符串的值转换为等效的 Unicode 字符,代码如下:示例 实时演示使用 System;公共类演示{    公共静态无效 Main(){       布尔 res;       字符 ch;       res = Char.TryParse("10",out ch);       Console.WriteLine(res);       Console.WriteLine(ch.ToString());    } }输出这将产生以下输出:False示例现在让我们看另一个示例: 实时演示使用 System;公共类演示{    公共静态无效 Main(){       布尔 res;       字符 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 位有符号整数,代码如下:示例 实时演示使用 System;公共类演示{    公共静态无效 Main() {       双精度 d = 5.646587687;       Console.Write("值 = " + d);       长 res = BitConverter.DoubleToInt64Bits(d);       Console.Write("64 位有符号整数 = " + res);    } }输出这将产生以下输出:值 = 5.646587687 64 位 有符号 整数 = 4618043510978159912示例让我们看另一个示例: 实时演示使用 System;公共类演示{    公共静态无效 Main() {       双精度 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 文件时间,代码如下:示例 实时演示使用 System;公共类演示{    公共静态无效 Main() {       DateTime d = DateTime.Now;       Console.WriteLine("日期 = {0}",d);       长 res = d.ToFileTime();       Console.WriteLine("Windows 文件时间 = {0}",res);    } }输出这将产生以下输出:日期 = 2019/10/16 上午 8:17:26 Windows 文件 时间 = 132156874462559390示例让我们看另一个示例: 实时演示使用 System;公共类演示{    公共静态无效 Main() {       DateTime d = 新 DateTime(2019, 05, 10, 6, ... 阅读更多

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

AmitDiwan
更新于 2019-12-11 07:15:20

2K+ 次浏览

switch 语句允许将变量与其值列表进行相等性测试。每个值称为一个 case,并且正在切换的变量会针对每个 switch case 进行检查。示例以下是如何在 switch 语句中使用字符串的示例: 实时演示使用 System;公共类演示{    公共静态无效 Main(String[] args){       字符串 grades = "A1";       switch (grades) {          case "A1":             Console.WriteLine("非常好!");             break;          case "A2":       ... 阅读更多

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

AmitDiwan
更新于 2019-12-11 07:13:32

70 次浏览

要获取一个迭代遍历 StringDictionary 的枚举器,代码如下:示例 实时演示使用 System.Collections;使用 System.Collections.Specialized;公共类演示{    公共静态无效 Main() {       StringDictionary strDict1 = 新 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 元素...");       针对(字典条目 de 在 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 循环的示例 - 实时演示使用 System; 使用 System.Collections.Generic; 公共类 Demo {    公共静态 void Main(){       LinkedList linkedList = new LinkedList();       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("Count ... 阅读更多

获取在 C# 中遍历 SortedSet 的枚举器

AmitDiwan
更新于 2019-12-11 07:10:21

61 次查看

要获取遍历 SortedSet 的枚举器,代码如下 - 示例实时演示使用 System; 使用 System.Collections.Generic; 公共类 Demo {    公共静态 void Main() {       SortedSet set1 = new SortedSet();       set1.Add("AB");       set1.Add("BC");       set1.Add("CD");       set1.Add("EF");       Console.WriteLine("SortedSet1 中的元素...");       foreach (string res in set1) {          Console.WriteLine(res);       }       SortedSet set2 = new SortedSet();       set2.Add("BC");       set2.Add("CD");       set2.Add("DE");       ... 阅读更多

广告

© . All rights reserved.