找到 34423 篇文章,关于编程

C#程序合并两个字典

Chandu yadav
更新于 2020-06-22 10:52:52

1K+ 次浏览

设置两个字典 −Dictionary < string, int > dict1 = new Dictionary < string, int > (); dict1.Add("laptop", 1); dict1.Add("desktop", 2); Dictionary < string, int > dict2 = new Dictionary < string, int > (); dict2.Add("desktop", 3); dict2.Add("tablet", 4); dict2.Add("mobile", 5); 现在使用 HashSet 和 UnionWith() 方法合并这两个字典 −HashSet < string > hSet = new HashSet < string > (dict1.Keys); hSet.UnionWith(dict2.Keys); 完整的代码如下 −示例 using System; using System.Collections.Generic; class Program {    static void Main() {       Dictionary < string, int > dict1 = new Dictionary < string, int > ();     ... 阅读更多

如何使用C#查找文件?

George John
更新于 2020-06-22 10:53:53

103 次浏览

使用 C# 中的 GetDirectories 获取首先出现的子文件夹列表 −Directory.GetDirectories 现在循环遍历这些目录,并对子文件夹重复此过程。string path = @"d:/New/Myfile"; string[] myDir = Directory.GetDirectories(path, "xml", SearchOption.AllDirectories); Console.WriteLine(myDir.Length.ToString()); foreach (string res in myDir) Console.WriteLine(res);

C#中的链表

Samual Sam
更新于 2020-06-22 10:55:35

2K+ 次浏览

C# 中的 System.Collections.Generic 命名空间提供了 LinkedList。LinkedList 类允许快速插入和删除列表中的元素。C# LinkedList 类使用链表的概念。它允许我们快速插入和删除元素。它可以包含重复元素。它位于 System.Collections.Generic 命名空间中。示例  在线演示 using System; using System.Collections.Generic; class Demo {    static void Main() {       LinkedList < string > l = new LinkedList < string > ();       l.AddLast("one");       l.AddLast("two");       l.AddLast("three");     ... 阅读更多

如何在C#中编写“Hello World”?

karthikeya Boyini
更新于 2020-06-22 10:56:46

445 次浏览

要在 C# 中打印“Hello World”,请使用 Console.WriteLine。让我们来看一个显示文本的基本 C# 程序 −示例  在线演示 using System; using System.Collections.Generic; using System.Text; namespace Program {    class MyApplication {       static void Main(string[] args) {          Console.WriteLine("Hello World");          Console.Read();       }    } }输出 Hello World 在上面,我们使用 WriteLine() 方法显示了文本“Hello World”。输出使用控制台显示 −Console.WriteLine("Hello World");

如何使用C#检查字符串是否为回文?

Ankith Reddy
更新于 2020-06-22 10:54:50

374 次浏览

假设我们需要找到以下字符串是否为回文 −str = "Level"; 为此,将字符串转换为字符数组以检查每个字符 −char[] ch = str.ToCharArray(); 现在查找反转 −Array.Reverse(ch); 使用 Equals 方法查找反转是否等于原始数组 −bool res = str.Equals(rev, StringComparison.OrdinalIgnoreCase); 完整的代码如下 −示例  在线演示 using System; namespace Demo {    class Program {       static void Main(string[] args) {          string str, rev;          str = "Level";          char[] ch ... 阅读更多

如何使用C#将十进制转换为二进制?

Samual Sam
更新于 2020-06-22 10:57:36

323 次浏览

假设我们要将数字 48 转换为二进制。首先,设置它并使用 / 和 % 运算符,并循环直到值大于 1 −decVal = 48; while (decVal >= 1) {    val = decVal / 2;    a += (decVal % 2).ToString();    decVal = val; } 现在,显示二进制的每一位,如完整的代码所示 −示例  在线演示 using System; using System.Collections.Generic; using System.Text; namespace Demo {    class MyApplication {       static void Main(string[] args) {          int decVal;         ... 阅读更多

C#中try catch finally的流程控制

karthikeya Boyini
更新于 2020-06-22 10:58:29

576 次浏览

可以使用以下示例来理解 try、catch 和 finally 中的流程控制。在这里,我们正在除以两个数字 −示例  在线演示 using System; namespace ErrorHandlingApplication {    class DivNumbers {       int result;       DivNumbers() {          result = 0;       }       public void division(int num1, int num2) {          try {             result = num1 / num2;          } catch (DivideByZeroException e) {             Console.WriteLine("Exception caught: {0}", e);   ... 阅读更多

什么是C#中的非托管代码?

Samual Sam
更新于 2020-06-22 10:19:37

537 次浏览

以下是关于非托管代码的说明 −不受 CLR 控制的应用程序是非托管的 不安全代码或非托管代码是使用指针变量的代码块。unsafe 修饰符允许在非托管代码中使用指针。以下模块显示如何声明和使用指针变量。我们在这里使用了 unsafe 修饰符。让我们来看一个例子 −示例 static unsafe void Main(string[] args) {    int var = 20;    int* p = &var;    Console.WriteLine("Data is: {0} ", var);    Console.WriteLine("Address is: {0}", (int)p);    Console.ReadKey(); }

什么是C#中的拆箱?

karthikeya Boyini
更新于 2020-06-22 10:19:54

167 次浏览

装箱是隐式的,拆箱是显式的。拆箱是将由装箱创建的引用类型显式转换回值类型。让我们来看一个 C# 中变量和对象的示例 −// int int x = 30; // 装箱 object obj = x; // 拆箱 int unboxInt = (int) obj; 以下是一个显示拆箱的示例 −int x = 5; ArrayList arrList = new ArrayList(); // 装箱 arrList.Add(x); // 拆箱 int y = (int) arrList [0];

C#中锯齿数组的元素类型是什么?

Samual Sam
更新于 2020-06-22 10:21:04

104 次浏览

锯齿数组是数组的数组,因此其元素是引用类型,并初始化为 null。让我们看看如何使用锯齿数组 −声明锯齿数组 −int [][] marks; 现在,让我们对其进行初始化,其中 marks 是 5 个整数的数组 −int[][] marks = new int[][]{new int[]{ 40, 57 }, new int[]{ 34, 55 }, new int[]{ 23, 44 }, new int[]{ 56, 78 }, new int[]{ 66, 79 } }; 现在让我们看看 C# 中锯齿数组的完整示例,并学习如何实现它 −示例  在线演示 using System; namespace MyApplication ... 阅读更多

广告
© . All rights reserved.