找到 34423 篇文章,关于编程

C#程序获取当前星期几

Ankith Reddy
更新于 2020年6月23日 07:31:14

14K+ 浏览量

使用 DateTime.DayOfWeek 属性显示当前星期几。DayOfWeek wk = DateTime.Today.DayOfWeek; 现在,显示“wk”将为您提供当前星期几。让我们看看获取当前星期几的完整代码。示例 在线演示using System; using System.Linq; public class Demo {    public static void Main() {       DayOfWeek wk = DateTime.Today.DayOfWeek;       Console.WriteLine(wk);    } }输出Wednesday

C#程序检查序列的元素是否满足条件

karthikeya Boyini
更新于 2020年6月23日 07:30:47

293 浏览量

使用 All() 方法检查序列的元素是否满足条件。即使只有一个元素不满足设定的条件,All() 方法也会返回 False。要设置条件,请使用 Lambda 表达式。下面显示了一个条件,用于检查所有元素是否都大于 20。myArr.AsQueryable().All(val => val > 20);让我们来看一个例子。示例 在线演示using System; using System.Linq; class Demo {    static void Main() {       int[] myArr = {7, 15, 22, 30, 40};       // 检查所有数组元素是否都大于 20       bool res = myArr.AsQueryable().All(val => val > 20);       Console.WriteLine(res);    } }输出False

C#程序将类型转换为其 IEnumerable 等效项

Arjun Thakur
更新于 2020年6月23日 07:21:04

366 浏览量

使用 AsEnumerable() 方法将类型转换为其 IEnumerable 等效项。它是一个扩展方法。在我们的示例中,我们设置了一个数组。int[] myArr = new int[10]; myArr[0] = 1; myArr[1] = 2; myArr[2] = 3; myArr[3] = 4; myArr[4] = 5;现在,我们使用了 AsEnumerable() 方法进行转换。myArr.AsEnumerable();示例 在线演示using System; using System.Linq; class Demo {    static void Main() {       int[] myArr = new int[10];       myArr[0] = 1;       myArr[1] = 2;       myArr[2] = 3;       myArr[3] = 4;       myArr[4] = 5;       myArr[5] = 6;       myArr[6] = 7;       myArr[7] = 8;       myArr[8] = 9;       myArr[9] = 10;       // AsEnumerable       var a = myArr.AsEnumerable();       // 显示       foreach (var item in a) {          Console.WriteLine(item);       }    } }输出1 2 3 4 5 6 7 8 9 10

C#中两个DateTime之间以毫秒为单位的差值

Samual Sam
更新于 2020年6月23日 07:21:31

7K+ 浏览量

假设以下是我们日期的两个 DateTime 对象。DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);使用 TimeSpan 查找这两个日期之间的差值。TimeSpan ts = date2 - date1;现在要获取毫秒数,请使用以下属性:ts.TotalMilliseconds让我们看看完整的代码。示例 在线演示using System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 8, 11, 08, 15, 20);       DateTime date2 = new DateTime(2018, 8, 11, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("秒数(差值)= {0}", ts.TotalMilliseconds);    } }输出秒数(差值)= 10745000

C# Console.WindowLeft 属性

Ankith Reddy
更新于 2020年6月23日 07:21:53

194 浏览量

WindowsLeft 属性获取或设置控制台窗口区域相对于屏幕缓冲区的左端位置。声明一个整数变量以获取最左端的位置。int left;现在,使用 Console.WindowLeft 属性。left = Console.WindowLeft让我们看看完整的示例。示例 在线演示using System; class Demo {    static void Main() {       int left;       left = Console.WindowLeft;       Console.WriteLine("控制台窗口的左端位置 = "+left);    } }输出注意:输出可能根据控制台窗口的位置而有所不同控制台窗口的左端位置 = 0

在C#中计算两个日期之间的分钟数

George John
更新于 2020年6月23日 07:22:38

19K+ 浏览量

首先,设置两个日期。DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);现在,计算两个日期之间的差值。TimeSpan ts = date2 - date1;计算分钟数。ts.TotalMinutes让我们看看完整的代码。示例 在线演示using System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("分钟数(差值)= {0}", ts.TotalMinutes);    } }输出分钟数(差值)= 47699.0833333333

C#程序获取两个日期之间的秒差

karthikeya Boyini
更新于 2020年6月23日 07:22:16

6K+ 浏览量

设置两个日期。DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);现在计算两个日期之间的差值。TimeSpan ts = date2 - date1;进一步计算秒差。ts.TotalSeconds让我们看看完整的代码。示例 在线演示using System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 7, 15, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("秒数(差值)= {0}", ts.TotalSeconds);    } }输出秒数(差值)= 10745

C# Console.WindowHeight 属性

Samual Sam
更新于 2020年6月23日 07:22:58

169 浏览量

WindowHeight 属性获取或设置控制台窗口的高度。声明一个变量。int height;现在,获取当前窗口的高度。height = Console.WindowHeight;以下是完整的示例:示例 在线演示using System; using System.Numerics; using System.Globalization; class Demo {    static void Main() {       int height;       height = Console.WindowHeight;       Console.WriteLine("当前窗口高度 = "+height);    } }输出当前窗口高度 = 0

C#程序在链表中给定节点之后添加节点

Chandu yadav
更新于 2020年6月23日 07:24:57

230 浏览量

设置一个 LinkedList 并添加元素。string [] students = {"Beth", "Jennifer", "Amy", "Vera"}; LinkedList list = new LinkedList(students);首先,在末尾添加一个新节点。var newNode = list.AddLast("Emma");现在,使用 AddAfter() 方法在给定节点之后添加节点。list.AddAfter(newNode, "Matt");以下是完整的代码。示例 在线演示using System; using System.Collections.Generic; class Demo {    static void Main() {       string [] students = {"Beth", "Jennifer", "Amy", "Vera"};       LinkedList list = new LinkedList(students);       foreach (var stu in list) {          Console.WriteLine(stu);       }       // ... 阅读更多

C#程序确定两个日期之间的小时差

Samual Sam
更新于 2020年6月23日 07:24:08

10K+ 浏览量

设置两个日期。DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20); DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);现在,获取两个日期之间的差值。TimeSpan ts = date2 - date1;获取结果,即小时差。ts.TotalHours让我们看看完整的代码。示例 在线演示using System; using System.Linq; public class Demo {    public static void Main() {       DateTime date1 = new DateTime(2018, 7, 15, 08, 15, 20);       DateTime date2 = new DateTime(2018, 8, 17, 11, 14, 25);       TimeSpan ts = date2 - date1;       Console.WriteLine("小时数(差值)= {0}", ts.TotalHours);    } }输出小时数(差值)= 794.984722222222

广告
© . All rights reserved.