找到 34423 篇文章,关于编程

C# 程序逐行读取文件

Arjun Thakur
更新于 2020年6月23日 08:27:40

259 次浏览

使用 ReadAllLines() 方法逐行读取文件。假设我们有一个名为“new.txt”的文件,其中包含以下几行:One Two Three。首先,设置要读取的文件路径:String myPath = "new.txt"; 现在将其添加到字符串数组中以逐行获取:String[] fLine = File.ReadAllLines(myPath); 假设您需要获取第一行,则使用:fLine[0]。以下是逐行读取文件的完整示例:示例 using System; using System.IO; public class Demo {    public static void Main() {       String myPath = "new.txt";     ... 阅读更多

C# 中的 LinkedList AddLast 方法

Samual Sam
更新于 2020年6月23日 08:29:12

332 次浏览

声明一个字符串数组:string [] students = {"Jenifer", "Angelina", "Vera"};将其添加到 LinkedList 中:string [] students = {"Jenifer", "Angelina", "Vera"};现在,使用 AddLast() 方法在末尾添加一个节点:list.AddLast("Anne");示例 使用 System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Jenifer", "Angelina", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // 在末尾添加一个节点       Console.WriteLine("Node added at the last...");       list.AddLast("Anne"); ... 阅读更多

C# 可查询 SequenceEqual() 方法

Chandu yadav
更新于 2020年6月23日 08:29:40

95 次浏览

要检查两个序列是否相等,请使用 SequenceEqual() 方法。首先,设置序列:Employee emp1 = new Employee { EmployeeRank = 4, EmpName = "Amit", EmpMarks = 90 }; Employee emp2 = new Employee { EmployeeRank = 5, EmpName = "Raman", EmpMarks = 95 }; List employee1 = new List { emp1, emp2 }; List employee2 = new List { emp1, emp2 }; 现在,查找序列是否相等:employee1.AsQueryable().SequenceEqual(employee2); 这是一个显示结果的示例:示例 使用 System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       Employee ... 阅读更多

C# Linq SelectMany 方法

karthikeya Boyini
更新于 2020年6月23日 08:30:14

798 次浏览

使用 SelectMany 方法将元素折叠到单个集合中,例如错误。一个例子是将字符串转换为字符数组。以下是我们的字符串数组:string[] str = { "Mobile", "Laptop", "Tablet" }; 现在,转换为字符数组:str.SelectMany(item => item.ToCharArray()); 示例 使用 System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       string[] str = { "Mobile", "Laptop", "Tablet" };       var res = str.SelectMany(item => item.ToCharArray());       Console.WriteLine("String converted to character array: ");       foreach (char letter in res) {          Console.Write(letter);       }    } } 输出 String converted to character array: MobileLaptopTablet

C# Linq Select 方法

George John
更新于 2020年6月23日 08:20:09

2K+ 次浏览

使用 Select 方法修改数组中的元素。以下是我们的字符串数组:string[] stationery = { "diary", "board", "pencil", "whiteboard" }; Select 方法还指定 Lambda 表达式,如下所示:示例 使用 System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       string[] stationery = { "diary", "board", "pencil", "whiteboard" };       var res = stationery.AsQueryable().Select((item, index) => new { result = item.Substring(0, index + 4) });       foreach (var str in res) {          Console.WriteLine("{0}", str);       }    } } 输出 { result = diar } { result = board } { result = pencil } { result = whitebo }

C# 程序查找列表中元素的立方

Samual Sam
更新于 2020年6月23日 08:20:38

482 次浏览

使用 Select 方法和 Lambda 表达式计算元素的立方。以下是我们的列表:List list = new List { 2, 4, 5, 7 }; 现在,使用 Select() 方法并计算立方:list.AsQueryable().Select(c => c * c * c); 以下是完整的示例:示例 使用 System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       List list = new List { 2, 4, 5, 7 };       Console.WriteLine("Elements...");       // 初始列表 javascript:void(0)       foreach (int n in list)       Console.WriteLine(n);     ... 阅读更多

C# Console.WindowTop 属性

Ankith Reddy
更新于 2020年6月23日 08:20:56

135 次浏览

WindowsTop 属性用于获取或设置控制台窗口区域相对于屏幕缓冲区的顶部位置。声明一个整数变量以获取顶部位置:int top; 现在,使用 Console.WindowTop 属性:top = Console.WindowTop; 让我们看看完整的示例:示例 使用 System; class Demo {    static void Main() {       int top;       top = Console.WindowTop;       Console.WriteLine("Top position of the Console window = "+top);    } } 输出 Top position of the Console window = 0

C# Console BufferWidth 属性

karthikeya Boyini
更新于 2020年6月23日 08:21:16

153 次浏览

使用 BufferWidth 获取或设置缓冲区区域的宽度。像这样使用该属性:Console.BufferWidth。让我们看看完整的示例:示例 使用 System; class Demo {    static void Main() {       Console.WriteLine("Buffer width (columns) = "+Console.BufferWidth);    } } 输出 Buffer width (columns) = 0

C# Linq Reverse 方法

Arjun Thakur
更新于 2020年6月23日 08:21:46

828 次浏览

使用 Reverse 方法反转数组中的元素。这是我们的字符数组:char[] ch = { 't', 'i', 'm', 'e' }; 现在使用 Reverse() 方法和 AsQueryable() 方法来获取反转后的结果:ch.AsQueryable().Reverse(); 让我们看看完整的代码:示例 使用 System; using System.Linq; using System.Collections.Generic; public class Demo {    public static void Main() {       char[] ch = { 't', 'i', 'm', 'e' };       Console.Write("String = ");       foreach(char arr in ch) {          Console.Write(arr);       }       IQueryable res = ch.AsQueryable().Reverse();       Console.Write("Reversed String = ");       foreach (char c in res) {          Console.Write(c);       }    } } 输出 String = time Reversed String = emit

C# 中的完整日期长时制 ("F") 格式说明符

Samual Sam
更新于 2020年6月23日 08:22:05

176 次浏览

完整日期长时制标准格式说明符的自定义日期和时间格式字符串由当前的 DateTimeFormatInfo.FullDateTimePattern 属性定义。自定义格式字符串为:dddd, dd MMMM yyyy HH:mm:ss 示例 使用 System; using System.Globalization; class Demo {    static void Main() {       DateTime myDate = new DateTime(2018, 8, 13, 9, 15, 0);       Console.WriteLine(myDate.ToString("F", CultureInfo.CreateSpecificCulture("en-US")));    } } 输出 Monday, August 13, 2018 9:15:00 AM

广告
© . All rights reserved.