找到 34423 篇文章 关于编程
636 次浏览
使用 DaysInMonth 显示月份的天数。将年份和月份作为参数添加到 DaysInMonth() 方法中 −DateTime.DaysInMonth(2018, 8);以下是一个例子 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { Console.WriteLine("今天 = {0}", DateTime.Today); int num_days = DateTime.DaysInMonth(2018, 8); Console.WriteLine("八月份的天数: "+num_days); } }输出今天 = 2018/9/4 0:00:00 八月份的天数: 31
3K+ 次浏览
要显示下一天,请使用 AddDays() 方法和值 +1 来获取下一天。首先,使用以下方法获取当前日期 −DateTime.Today现在,将 1 添加到 AddDays() 方法中以获取下一天 −DateTime.Today.AddDays(1)以下是代码 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { Console.WriteLine("今天 = {0}", DateTime.Today); Console.WriteLine("昨天 = {0}", DateTime.Today.AddDays(-1)); Console.WriteLine("明天 = {0}", DateTime.Today.AddDays(1)); } }输出今天 = 2018/9/4 0:00:00 昨天 = 2018/9/3 0:00:00 明天 = 2018/9/5 0:00:00
4K+ 次浏览
要显示前一天,请使用 AddDays() 方法和值 -1 来获取前一天。首先,使用以下方法获取当前日期 −DateTime.Today现在,将 -1 添加到 AddDays() 方法中以获取前一天 −DateTime.Today.AddDays(-1)以下是代码 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { Console.WriteLine("今天 = {0}", DateTime.Today); Console.WriteLine("昨天 = {0}", DateTime.Today.AddDays(-1)); } }输出今天 = 2018/9/4 0:00:00 昨天 = 2018/9/3 0:00:00
4K+ 次浏览
声明一个二维数组 −string[, ] array = new string[3, 3];设置数组中的元素 −array[0, 0] = "One"; array[0, 1] = "Two"; array[0, 2] = "Three"; array[1, 0] = "Four"; array[1, 1] = "Five"; array[1, 2] = "Six"; array[2, 0] = "Seven"; array[2, 1] = "Eight"; array[2, 2] = "Nine";现在,获取上界以获取要遍历数组的维度 −int uBound0 = array.GetUpperBound(0); int uBound1 = array.GetUpperBound(1);迭代嵌套循环,直到上述两个值,如下面的代码所示 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { ... 阅读更多
8K+ 次浏览
设置一个具有零个元素的列表 −List myList = new List();现在检查列表是否为空或为 null −Console.WriteLine(myList == null);上面返回“False”,即列表不为 null - 列表为空。让我们看看完整的代码 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List myList = new List(); // 返回 false,即空列表(不是 null 列表) Console.WriteLine(myList == null); } }输出False
369 次浏览
首先,设置两个 TimeSpan −TimeSpan t1 = TimeSpan.FromMinutes(2); TimeSpan t2 = TimeSpan.FromMinutes(1);要添加它,请使用 Subtract() 方法 −imeSpan res = t1.Subtract(t2);这是完整的代码 −示例 在线演示using System; using System.Linq; public class Demo { public static void Main() { TimeSpan t1 = TimeSpan.FromMinutes(2); TimeSpan t2 = TimeSpan.FromMinutes(1); Console.WriteLine("第一个 TimeSpan: "+t1); Console.WriteLine("第二个 TimeSpan: "+t2); // 减法 TimeSpan res = t1.Subtract(t2); Console.WriteLine("结果 TimeSpan: "+res); } }输出第一个 TimeSpan: 00:02:00 第二个 TimeSpan: 00:01:00 结果 TimeSpan: 00:01:00
2K+ 次浏览
C# 中存在空列表。要检查列表是否为空,请将其与 null 字面量进行比较。像这样设置 null −List myList = null;现在,要检查 null,请使用等号运算符 −myList == null;以下是一个示例 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List myList = null; // 检查 null Console.WriteLine(myList == null); } }输出True
6K+ 次浏览
使用 Distinct() 方法从 C# 列表中删除重复项。首先,添加一个新列表 −List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50); arr1.Add(30); arr1.Add(40); arr1.Add(50);要删除重复元素,请使用 Distinct() 方法,如下所示 −List distinct = arr1.Distinct().ToList();这是完整的代码 −示例 在线演示using System; using System.Collections.Generic; using System.Linq; public class Demo { public static void Main() { List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50); arr1.Add(30); arr1.Add(40); ... 阅读更多
2K+ 次浏览
使用 GetRange() 方法获取元素的范围 −首先,设置一个列表并添加元素 −List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50);现在,在一个新列表中获取索引 1 和 3 之间的元素范围 −List myList = arr1.GetRange(1, 3);这是完整的代码 −示例 在线演示using System; using System.Collections.Generic; public class Demo { public static void Main() { List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50); Console.WriteLine("初始列表 ..."); ... 阅读更多
3K+ 次浏览
使用 InsertRange() 方法在 C# 中的现有列表之间插入列表。通过此方法,您可以轻松地向现有列表添加多个元素。让我们首先设置一个列表 −List arr1 = new List(); arr1.Add(10); arr1.Add(20); arr1.Add(30); arr1.Add(40); arr1.Add(50);现在,让我们设置一个数组。此数组的元素就是我们将添加到上述列表中的元素 −int[] arr2 = new int[4]; arr2[0] = 60; arr2[1] = 70; arr2[2] = 80; arr2[3] = 90;我们将上述元素添加到列表中 −arr1.InsertRange(5, arr2);这是完整的代码 −示例 在线演示using System; using System.Collections.Generic; public ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP