找到 34423 篇文章,关于编程
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 > (); ... 阅读更多
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);
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"); ... 阅读更多
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");
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 ... 阅读更多
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; ... 阅读更多
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); ... 阅读更多
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(); }
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 ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP