找到 34423 篇文章 相关编程
44 次浏览
以下为字符串数组 - string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" };首先,连接它 - string.Join(" ", str);现在要分离上述连接的字符串,请使用 Split() 方法,如下面的代码所示 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" }; // 连接单词 字符串 res = string.Join(" ", str); Console.WriteLine("连接的字符串... " + res); 字符串[] convert = res.Split(' '); Console.WriteLine("分离连接的字符串..."); ... 阅读更多
195 次浏览
声明一个字符串并添加元素 - string[] str = { "One", "Two", "Three", "Four", "Five" };使用 Join() 方法连接单词 - string res = string.Join(" ", str);让我们看看完整的代码 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = { "One", "Two", "Three", "Four", "Five" }; // 连接单词 字符串 res = string.Join(" ", str); Console.WriteLine(res); } }输出One Two Three Four Five
507 次浏览
声明并初始化一个数组 - string[] str = new string[] { "Cat", "Mat", "Rat" };现在,使用 IndexOf() 方法查找单词“Mat”的索引 - Array.IndexOf(str, "Mat");以下是代码 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = new string[] { "Cat", "Mat", "Rat" }; Console.WriteLine("我们的数组 ="); 对于(int i = 0; i < str.Length; i++) { 字符串 res = str[i]; Console.WriteLine(res); } int findIndex = Array.IndexOf(str, "Mat"); Console.Write("在以下索引处找到元素 Mat:"); Console.WriteLine(findIndex); } }输出我们的数组 = Cat Mat Rat 在以下索引处找到元素 Mat:1
4K+ 次浏览
要创建一个空字符串数组 - string[] str = new string[] {};在上面,我们没有向数组添加元素,因为它为空。即使我们遍历数组,它也不会显示任何内容,如下所示 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = new string[] {}; Console.WriteLine("由于字符串数组为空,因此不会显示元素..."); 对于(int i = 0; i < str.Length; i++) { 字符串 res = str[i]; Console.WriteLine(res); } } }输出由于字符串数组为空,因此不会显示元素...
2K+ 次浏览
创建一个字符串数组 - string[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" };循环直到数组的长度 - for (int i = 0; i < str.Length; i++) { 字符串 res = str[i]; Console.WriteLine(res); }以下是完整的代码 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = new string[] { "Videos", "Tutorials", "Tools", "InterviewQA" }; Console.WriteLine("字符串数组..."); 对于(int i = 0; i < str.Length; i++) { 字符串 res = str[i]; Console.WriteLine(res); } } }输出字符串数组... Videos Tutorials Tools InterviewQA
3K+ 次浏览
首先,设置一个数组 - string[] str = new string[]{ "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" };要获取最后一个元素的值,请获取长度并显示以下值 - str[str.Length - 1]以上返回最后一个元素。以下是完整的代码 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { 字符串[] str = new string[] { "Java", "HTML", "jQuery", "JavaScript", "Bootstrap" }; Console.WriteLine("数组..."); foreach(字符串 res in str) { Console.WriteLine(res); } Console.WriteLine("最后一个元素:" + str[str.Length - 1]); } }输出数组... Java HTML jQuery JavaScript Bootstrap 最后一个元素:Bootstrap
10K+ 次浏览
在 Join 方法下调用一个方法来连接单词 - string.Join(" ", display())现在设置一个字符串数组 - string[] str = new string[5];添加各个元素 - str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt";并从方法中返回相同的字符串数组 - return str;以下是完整的代码 - 示例 Live Demo使用 System; 公共类演示 { 公共静态无效主() { Console.WriteLine(string.Join(" ", display())); } 静态字符串[] display() { 字符串[] str = new string[5]; // 字符串数组元素 str[0] = "My"; str[1] = "name"; str[2] = "is"; str[3] = "Brad"; str[4] = "Pitt"; 返回 str; } }输出My name is Brad Pitt
228 次浏览
使用 ReadToEnd() 方法将文件的内容读取到字符串中。在 StreamReader 下设置它并读取文件 - using (StreamReader sr = new StreamReader("new.txt")){ 字符串 res = sr.ReadToEnd(); Console.WriteLine(res); }以下是完整的代码 - 示例 Live Demo使用 System.IO; 使用 System; 公共类演示 { 公共静态无效主() { 使用(StreamWriter sw = new StreamWriter("new.txt")) { sw.WriteLine("One"); sw.WriteLine("Two"); } 使用(StreamReader sr = new StreamReader("new.txt")) { 字符串 res = sr.ReadToEnd(); ... 阅读更多
454 次浏览
要读取文本文件,请在 C# 中使用 StreamReader 类。添加要读取的文件的名称 - StreamReader sr = new StreamReader("hello.txt");使用 ReadLine() 方法并将文件内容获取到字符串中 -using (StreamReader sr = new StreamReader("hello.txt")) { str = sr.ReadLine(); } Console.WriteLine(str);让我们看看下面的代码 -示例 在线演示using System.IO; using System; public class Program { public static void Main() { string str; using (StreamWriter sw = new StreamWriter("hello.txt")) { sw.WriteLine("Hello"); sw.WriteLine("World"); } ... 阅读更多
407 次浏览
orderby 用于在 C# 中根据指定字段以特定顺序对集合中的元素进行排序。顺序可以是升序或降序。以下是我们的带有元素的列表 -List myList = new List(); // 添加元素 myList.Add("iOS by Apple"); myList.Add("Android by Google"); myList.Add("Symbian by Nokia");现在,使用 Orderby 按降序排列元素 -var myLen = from element in myList orderby element.Length descending select element;以下是完整的代码 -示例 在线演示using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List myList = new ... 阅读更多
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP