找到 34423 篇文章 关于编程
822 次浏览
通过方法重载,您可以在相同的范围内为同一个函数名提供多个定义。函数的定义必须通过参数列表中参数的类型和/或数量来区分。让我们来看一个例子。在这个例子中,调用将转到具有单个参数的方法 - 例子 using System; class Student { static void DisplayMarks(int marks1 = 90) { Console.WriteLine("具有一个参数的方法!"); } static void DisplayMarks(int marks1, int marks2 = 95) { Console.WriteLine("具有两个参数的方法!"); } ... 阅读更多
156 次浏览
ArrayList是C#中一种非泛型集合类型,它可以动态调整大小。让我们看看如何在C#中初始化ArrayList - ArrayList arr= new ArrayList();向ArrayList添加项 - ArrayList arr1 = new ArrayList(); arr1.Add(30); arr1.Add(70);让我们来看一个在C#中实现ArrayList的完整示例。这里我们有两个ArrayList。第二个ArrayList被添加到第一个列表中。例子 using System; using System.Collections; public class MyClass { public static void Main() { ArrayList arr1 = new ArrayList(); arr1.Add(30); arr1.Add(70); ArrayList arr2 = ... 阅读更多
742 次浏览
初始化HashSet。var h = new HashSet(arr1);上面,我们已在HashSet中设置了一个数组。以下是数组 - string[] arr1 = { "electronics", "accessories”, "electronics", };以下是一个显示如何在C#中实现HashSet的示例 - 例子 using System; using System.Collections.Generic; using System.Linq; class Program { static void Main() { string[] arr1 = { "electronics", "accessories”, "electronics", }; Console.WriteLine(string.Join(",", arr1)); // HashSet var h = new HashSet(arr1); // 消除重复单词 string[] arr2 = h.ToArray(); Console.WriteLine(string.Join(",", arr2)); } }
4K+ 次浏览
要在以大写字母开头的单词之间添加空格,请尝试以下示例 - 首先,设置字符串。var str = "WelcomeToMyWebsite";如您在上面看到的,我们的字符串在大写字母前没有空格。要添加它,请使用LINQ,就像我们在下面所做的那样 - str = string.Concat(str.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');以下是放置以大写字母开头的单词之间空格的完整代码 - 例子 using System; using System.Linq; class Demo { static void Main() { var str = "WelcomeToMyWebsite"; Console.WriteLine("原始字符串:" + str); ... 阅读更多
558 次浏览
假设以下为字符串 - Welcome反转字符串后,单词应显示为 - emocleW使用reverse()方法并尝试以下代码来反转字符串中的单词 - 例子 using System; using System.Linq; class Demo { static void Main() { string str = "Welcome"; // 反转字符串 string res = string.Join(" ", str.Split(' ').Select(s => new String(s.Reverse().ToArray()))); Console.WriteLine(res); } }
378 次浏览
使用String.Format方法格式化DateTime。让我们来看一个例子 - 例子 using System; static class Demo { static void Main() { DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123); Console.WriteLine(String.Format("{0:y yy yyy yyyy}", d)); Console.WriteLine(String.Format("{0:M MM MMM MMMM}", d)); Console.WriteLine(String.Format("{0:d dd ddd dddd}", d)); } }上面我们首先设置了DateTime类对象 - DateTime d = new DateTime(2018, 2, 8, 12, 7, 7, 123);为了格式化,我们使用了String.Format()方法并以不同的格式显示日期。String.Format("{0:y yy yyy yyyy}", d) String.Format("{0:M MM MMM MMMM}", d) String.Format("{0:d dd ddd dddd}", d)
1K+ 次浏览
序列化将对象转换为字节流,并将其转换为可以写入流的形式。这样做是为了将其保存到内存、文件或数据库中。序列化可以执行为 - 二进制序列化所有成员,即使是只读成员,也会被序列化XML序列化它将对象的公共字段和属性序列化为符合特定XML模式定义语言文档的XML流。让我们来看一个例子。首先设置流 - FileStream fstream = new FileStream("d:ew.txt", FileMode.OpenOrCreate); BinaryFormatter formatter=new BinaryFormatter();现在创建类的对象并调用具有三个参数的构造函数 - Employee ... 阅读更多
2K+ 次浏览
文件是存储在磁盘上的具有特定名称和目录路径的数据集合。当打开文件进行读取或写入时,它就变成了一个流。流的类型包括 - 字节流 - 它包括Stream、FileStream、MemoryStream和BufferedStream。字符流 - 它包括Textreader-TextWriter、StreamReader、StraemWriter和其他流。字节流包含将流中的数据视为字节的类。Stream类是其他字节流类的基类。以下是属性 - CanRead - 流是否支持读取CanWrite - 流是否支持写入Length - 流的长度System.IO命名空间包含 ... 阅读更多
611 次浏览
字典字典是C#中键值对的集合。字典包含在System.Collection.Generics命名空间中。声明字典 - IDictionary d = new Dictionary();添加元素 - IDictionary d = new Dictionary(); d.Add(1,97); d.Add(2,89); d.Add(3,77); d.Add(4,88);数组数组存储相同类型元素的固定大小的顺序集合。它由连续的内存位置组成。最低地址对应于第一个元素,最高地址对应于最后一个元素。定义数组 - int[] arr = new int[5];初始化并将元素设置为数组。int[] arr = new int[10] {3, 5, 35, 87, 56, 99, 44, 36, 78};
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP