找到 34423 篇 编程相关文章

C#程序:将Double值转换为Int64值

karthikeya Boyini
更新于 2020年6月23日 08:47:13

1K+ 次浏览

要将 Double 值转换为 Int64 值,请使用 Convert.ToInt64() 方法。Int64 表示 64 位有符号整数。假设我们的 double 值如下:double val = 23.951213e12;现在将其转换为 Int64:long longVal = Convert.ToInt64(val);让我们来看完整的示例。示例 在线演示using System; public class Demo { public static void Main() { double val = 23.951213e12; long longVal = Convert.ToInt64(val); Console.WriteLine("将 double {0:E} 转换为 Int64 {1:N0} 值", val, longVal); } }输出将 double 2.395121E+013 转换为 Int64 23,951,213,000,000 值

C#程序:将Byte值转换为Int32值

Chandu yadav
更新于 2020年6月23日 08:47:57

7K+ 次浏览

要将 Byte 值转换为 Int32 值,请使用 Convert.ToInt32() 方法。Int32 表示 32 位有符号整数。假设我们的 Byte 值如下:byte val = Byte.MaxValue;;现在将其转换为 Int32:int intVal = Convert.ToInt32(val);让我们来看完整的示例。示例 在线演示using System; public class Demo { public static void Main() { byte val = Byte.MaxValue;; int intVal = Convert.ToInt32(val); Console.WriteLine("将 byte {0} 转换为 Int32 {1} 值", val, intVal); } }输出将 byte 255 转换为 Int32 255 值

C#程序:将Int32值转换为decimal

Samual Sam
更新于 2020年6月23日 08:48:26

3K+ 次浏览

要将 Int32 值转换为 decimal,请使用 Convert.ToDecimal() 方法。Int32 表示 32 位有符号整数。假设我们的 Int32 值如下:int val = 2923;现在将其转换为 decimal:decimal decVal = Convert.ToDecimal(val);让我们来看完整的示例。示例 在线演示using System; public class Demo { public static void Main() { int val = 2923; decimal decVal = Convert.ToDecimal(val); Console.WriteLine("将 Int32 {0} 转换为 decimal {1:N2} 值", val, decVal); } }输出将 Int32 2923 转换为 decimal 2,923.00 值

C#中的ArgumentNullException

George John
更新于 2020年6月23日 08:49:16

659 次浏览

当向不接受 null 引用作为有效参数的方法传递 null 引用时引发的异常。让我们来看一个示例。当我们将 null 参数设置为 int.Parse() 方法时,将引发 ArgumentNullException,如下所示:示例using System; class Demo { static void Main() { string val = null; int res = int.Parse(val); // 抛出错误 } }输出当编译上述程序时,由于我们传递了 null 值,因此会抛出以下错误:未处理的异常:System.ArgumentNullException:值不能为 null。

获取C#三维数组的边界

Ankith Reddy
更新于 2020年6月23日 08:37:49

389 次浏览

要获取三维数组的边界,请在 C# 中使用 GetUpperBound() GetLowerBound() 方法。这些方法的参数是维度,例如:假设我们的数组是:int[, , ] arr = new int[3, 4, 5];对于三维数组,维度 0。arr.GetUpperBound(0) arr.GetLowerBound(0)对于三维数组,维度 1。arr.GetUpperBound(1) arr.GetLowerBound(1)对于三维数组,维度 2。arr.GetUpperBound(2) arr.GetLowerBound(2)让我们来看完整的示例。示例 在线演示using System; class Program { static void Main() { int[, , ] arr = new int[3, 4, 5]; Console.WriteLine("维度 0 上界:{0}", arr.GetUpperBound(0).ToString()); Console.WriteLine("维度 0 下界:..."); 阅读更多

获取C#三维数组的宽度和高度

karthikeya Boyini
更新于 2020年6月23日 08:37:18

230 次浏览

假设我们的三维数组是:int[,,] arr = new int[3,4,5];要获取高度和宽度,即行和列。Array.GetLength(0) – 行数 Array.GetLength(1) – 列数示例 在线演示using System; class Program { static void Main() { int[,,] arr = new int[3,4,5]; Console.WriteLine(arr.GetLength(0)); Console.WriteLine(arr.GetLength(1)); Console.WriteLine(arr.GetLength(2)); } }输出3 4 5

获取C#中三维数组的秩

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

117 次浏览

要获取三维数组的秩,请使用 Rank 属性。设置一个三维数组。int[,,] arr = new int[3,4,5]现在获取秩。arr.Rank让我们来看完整的代码。示例using System; class Program { static void Main() { int[,,] arr = new int[3,4,5] Console.WriteLine("数组的维度:" + arr.Rank); } }

C# Linq Zip 方法

Samual Sam
更新于 2020年6月23日 08:39:48

1K+ 次浏览

使用 Zip 方法和谓词合并序列。这是我们要合并的数组。int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" };现在让我们使用 Zip 方法合并这两个数组。intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two)以下是我们的代码。示例 在线演示using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] intArray = { 10, 20, 30, 40 }; string[] stringArray = { "Jack", "Tim", "Henry", "Tom" }; var mergedSeq = intArray.AsQueryable().Zip(stringArray, (one, two) => one + " " + two); foreach (var ele in mergedSeq) Console.WriteLine(ele); } }输出10 Jack 20 Tim 30 Henry 40 Tom

C# Linq LastorDefault 方法

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

2K+ 次浏览

使用 LastorDefault() 方法返回序列的最后一个元素,如果元素不存在则返回默认值。这是一个空列表。List val = new List { };现在以下代码将无法显示最后一个元素,因为列表为空。因此,将显示默认值,并且不会显示错误。val.AsQueryable().LastOrDefault();以下是代码。示例 在线演示using System; using System.Collections.Generic; using System.Linq; class Demo { static void Main() { List val = new List { }; double d = val.AsQueryable().LastOrDefault(); Console.WriteLine("默认值 = "+d); ... 阅读更多

C# Queryable Union 方法

karthikeya Boyini
更新于 2020年6月23日 08:40:48

162 次浏览

使用 Queryable Union 方法对两个序列执行联合操作。以下是我们的数组。int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 };现在,使用 Union 方法获取数组的联合。arr1.AsQueryable().Union(arr2);示例 在线演示using System; using System.Linq; using System.Collections.Generic; public class Demo { public static void Main() { int[] arr1 = { 29, 40, 15, 55, 70, 30, 90 }; int[] arr2 = { 30, 36, 40, 18, 15, 55, 75 }; IEnumerable res = arr1.AsQueryable().Union(arr2); foreach (int a in res) Console.WriteLine("{0} ", a); } }输出29 40 15 55 70 30 90 36 18 75

广告
© . All rights reserved.