找到 34423 篇文章,关于编程

C#程序:分离C#中连接的字符串

Chandu yadav
更新于 2020年6月22日 13:49:53

44 次浏览

下面的字符串数组:string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" };首先,连接它们:string.Join(" ", str);现在,要分离以上连接的字符串,请使用 Split() 方法,如下面的代码所示:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = { "Java", "AngularJS", "Python", "jQuery", "HTML5" };       // 连接单词       string res = string.Join(" ", str);       Console.WriteLine("连接的字符串... "+res);       string[] convert = res.Split(' ');       Console.WriteLine("分离连接的字符串..."); ... 阅读更多

C#程序:将单词连接成C#中的字符串

Arjun Thakur
更新于 2020年6月22日 13:50:17

195 次浏览

声明一个字符串并添加元素:string[] str = { "One", "Two", "Three", "Four", "Five" };使用 Join() 方法连接单词:string res = string.Join(" ", str);让我们看看完整的代码:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = { "One", "Two", "Three", "Four", "Five" };       // 连接单词       string res = string.Join(" ", str);       Console.WriteLine(res);    } }输出One Two Three Four Five

C#程序:查找字符串中单词的索引

Ankith Reddy
更新于 2020年6月22日 13:50:59

507 次浏览

声明并初始化一个数组:string[] str = new string[] {    "Cat",    "Mat",    "Rat" };现在,使用 IndexOf() 方法查找单词“Mat”的索引:Array.IndexOf(str, "Mat");下面的代码:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = new string[] {          "Cat",          "Mat",          "Rat"       };       Console.WriteLine("我们的数组 =");       for (int i = 0; i < str.Length; i++) {          string res = str[i];          Console.WriteLine(res);       }       int findIndex = Array.IndexOf(str, "Mat");       Console.Write("元素 Mat 位于以下索引: ");       Console.WriteLine(findIndex);    } }输出我们的数组 = Cat Mat Rat 元素 Mat 位于以下索引: 1

C#程序:创建空字符串数组

George John
更新于 2020年6月22日 13:51:23

4K+ 次浏览

要创建一个空字符串数组:string[] str = new string[] {};上面,我们没有向数组添加元素,因为它为空。即使我们遍历数组,它也不会显示任何内容,如下所示:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = new string[] {};       Console.WriteLine("字符串数组元素不会显示,因为它为空...");       for (int i = 0; i < str.Length; i++) {          string res = str[i];          Console.WriteLine(res);       }    } }输出字符串数组元素不会显示,因为它为空...

C#程序:使用for循环迭代字符串数组

Chandu yadav
更新于 2020年6月22日 13:52:06

2K+ 次浏览

创建一个字符串数组:string[] str = new string[] {    "Videos",    "Tutorials",    "Tools",    "InterviewQA" };循环到数组长度:for (int i = 0; i < str.Length; i++) {    string res = str[i];    Console.WriteLine(res); }这是完整的代码:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = new string[] {          "Videos",          "Tutorials",          "Tools",          "InterviewQA"       };           Console.WriteLine("字符串数组...");       for (int i = 0; i < str.Length; i++) {          string res = str[i];          Console.WriteLine(res);       }    } }输出字符串数组... Videos Tutorials Tools InterviewQA

C#程序:从数组中获取最后一个元素

karthikeya Boyini
更新于 2020年6月22日 13:40:53

3K+ 次浏览

首先,设置一个数组:string[] str = new string[]{    "Java",    "HTML",    "jQuery",    "JavaScript",    "Bootstrap" };要获取最后一个元素的值,请获取长度并显示以下值:str[str.Length - 1]以上返回最后一个元素。这是完整的代码:示例 在线演示using System; public class Demo {    public static void Main() {       string[] str = new string[] {          "Java",          "HTML",          "jQuery",          "JavaScript",          "Bootstrap"       };       Console.WriteLine("数组...");       foreach(string res in str) {          Console.WriteLine(res);       }       Console.WriteLine("最后一个元素:"+str[str.Length - 1]);    } }输出数组... Java HTML jQuery JavaScript Bootstrap 最后一个元素:Bootstrap

C#程序:从方法返回数组

karthikeya Boyini
更新于 2020年6月22日 13:41:19

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;下面的代码是完整的代码:示例 在线演示using System; public class Demo {    public static void Main() {       Console.WriteLine(string.Join(" ", display()));    }    static string[] display() {       string[] str = new string[5];       // 字符串数组元素       str[0] = "My";       str[1] = "name";       str[2] = "is";       str[3] = "Brad";       str[4] = "Pitt";       return str;    } }输出My name is Brad Pitt

C#程序:一次性将文件内容读取到字符串中

Samual Sam
更新于 2020年4月3日 10:36:03

228 次浏览

使用 ReadToEnd() 方法将文件的内容读取到字符串中。将其设置在 StreamReader 中并读取文件:using (StreamReader sr = new StreamReader("new.txt")){    string res = sr.ReadToEnd();    Console.WriteLine(res); }下面的代码是完整的代码:示例 在线演示using System.IO; using System; public class Demo {    public static void Main() {       using (StreamWriter sw = new StreamWriter("new.txt")) {          sw.WriteLine("One");          sw.WriteLine("Two");       }       using (StreamReader sr = new StreamReader("new.txt")) {          string res = sr.ReadToEnd();       ... 阅读更多

使用 StreamReader 在 C# 中读取文件

karthikeya Boyini
更新于 2020年4月3日 10:43:20

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");       }   ... 阅读更多

C# 中的 Orderby 子句

Samual Sam
更新于 2020年6月22日 13:45:07

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 ... 阅读更多

广告
© . All rights reserved.