找到 34423 篇文章 关于编程
3K+ 阅读量
要复制或克隆 C# 列表,首先设置一个列表 - List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); list1.Add("Four"); 现在声明一个字符串数组并使用 CopyTo() 方法进行复制。string[] arr = new string[20]; list1.CopyTo(arr); 让我们看看复制列表到一维数组的完整代码。示例 using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); list1.Add("Three"); ... 阅读更多
592 阅读量
设置字符串数组的值 - string[] names = new string[] {"Jack", "Tom"}; 现在使用 foreach 数组,将内容写入文件 - using (StreamWriter sw = new StreamWriter("names.txt")) { foreach (string s in names) { sw.WriteLine(s); } } 以下是一个示例,显示了一个流数组,用于将文本写入文件 - 示例 using System; using System.IO; namespace FileApplication { class Program { static void Main(string[] args) { string[] names = new string[] {"Jack", "Tom"}; using (StreamWriter sw = ... 阅读更多
32K+ 阅读量
使用 AddRange() 方法将第二个列表追加到现有列表。 这是列表一 - List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); 这是列表二 - List < string > list2 = new List < string > (); list2.Add("Three"); ist2.Add("Four"); 现在让我们追加 - list1.AddRange(list2); 让我们看看完整的代码。示例 using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List < string > list1 = new List < string > (); list1.Add("One"); list1.Add("Two"); ... 阅读更多
211 阅读量
标记为“只读”的字段只能在对象构造期间设置一次。它不能被更改 - 让我们看一个例子。class Employee { readonly int salary; Employee(int salary) { this.salary = salary; } void UpdateSalary() { //salary = 50000; // 编译错误 } } 在上面,我们已将 salary 字段设置为只读。 如果您更改它,则会发生编译时错误。这在上面的示例中显示。现在让我们看看如何检查数组是否为只读 - 示例 using ... 阅读更多
16K+ 阅读量
要在 C# 中向列表添加字符串值,请使用 Add() 方法。 首先,在 C# 中声明一个字符串列表 - List list1 = new List(); 现在添加字符串项 - myList.Add("Jack"); myList.Add("Ben"); myList.Add("Eon"); myList.Add("Tim"); 让我们看看完整的代码 - 示例 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo { public class Program { public static void Main(String[] args) { List myList = new List(); myList.Add("Jack"); myList.Add("Ben"); myList.Add("Eon"); myList.Add("Tim"); Console.WriteLine(myList.Count); } } }
685 阅读量
要向现有锯齿数组添加元素,只需使用新值设置元素的值即可。 假设您需要在以下位置添加一个元素 - a[3][1] 只需设置值 - a[3][1] = 500; 在上面,我们访问了锯齿数组中第 3 个数组的第一个元素。让我们看看完整的代码 - 示例 using System; namespace Demo { class Program { static void Main(string[] args) { int[][] x = new int[][]{new int[]{10, 20}, new int[]{30, 40}, new int[]{50, 60}, new int[]{ 70, 80 }, new int[]{ 90, 100 ... 阅读更多
8K+ 阅读量
要在 C# 中向列表添加整数值,请使用 Add() 方法。 首先,在 C# 中声明一个整数列表 - List list1 = new List(); 现在添加整数 - list1.Add(900); list1.Add(400); list1.Add(300); 让我们看看完整的代码 - 示例 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Demo { public class Program { public static void Main(String[] args) { List list1 = new List(); list1.Add(900); list1.Add(400); list1.Add(300); Console.WriteLine(list1.Count); } } }
761 阅读量
首先,声明一个列表 - var teams = new List(); 要向 C# 列表添加项,请使用 Add() 方法 - teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia"); 您可以尝试运行以下代码以在 C# 中向列表添加项 - 示例 using System; using System.Collections.Generic; public class Demo { public static void Main(string[] args) { var teams = new List(); teams.Add("US"); teams.Add("Canada"); teams.Add("India"); teams.Add("Australia"); Console.WriteLine("Elements..."); foreach (var countries in teams) { Console.WriteLine(countries); } } }
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP