日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

c# 无法将类型隐式转换_C#中的隐式类型数组

發布時間:2023/12/1 C# 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c# 无法将类型隐式转换_C#中的隐式类型数组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

c# 無法將類型隱式轉換

C#隱式類型數組 (C# Implicitly Typed Arrays)

Like implicitly typed variables, we can also declare an array without specifying its type such type of arrays are known as Implicitly typed arrays.

像隱式類型的變量一樣,我們也可以在不指定其類型的情況下聲明一個數組,這樣的數組類型稱為隱式類型的數組 。

The type of the array is determined by the compiler based on the initializer list.

數組的類型由編譯器根據初始化列表確定。

Syntax:

句法:

var array_name = new[] {initialize_list/elements};

Example:

例:

var arr1 = new[] { 10, 20, 30, 40, 50 };var arr2 = new[] { 10.0f, 20.1f, 30.2f, 40.3f, 50.4f };var arr3 = new[] { "Manju", "Amit", "Abhi", "Radib", "Prem" };

Here, arr1 will be determined as int[] (integer array), arr2 as float[] (float/single array), and arr3 as String[] (string array).

在這里,將arr1確定為int [] (整數數組),將arr2確定為float [] (浮點數/單數組),將arr3確定為String [] (字符串數組)。

C#代碼演示隱式類型數組的示例 (C# code to demonstrate example of implicitly typed arrays )

using System; using System.Text;namespace Test {class Program{static void Main(string[] args){var arr1 = new[] { 10, 20, 30, 40, 50 };var arr2 = new[] { 10.0f, 20.1f, 30.2f, 40.3f, 50.4f };var arr3 = new[] { "Manju", "Amit", "Abhi", "Radib", "Prem" };//printing type of the arrayConsole.WriteLine("Type of arr1: " + arr1.GetType());Console.WriteLine("Type of arr2: " + arr2.GetType());Console.WriteLine("Type of arr3: " + arr3.GetType());//printing the elementsConsole.WriteLine("arr1 elements...");foreach (var item in arr1){Console.Write(item + " ");}Console.WriteLine();Console.WriteLine("arr2 elements...");foreach (var item in arr2){Console.Write(item + " ");}Console.WriteLine();Console.WriteLine("arr3 elements...");foreach (var item in arr3){Console.Write(item + " ");}Console.WriteLine();//hit ENTER to exitConsole.ReadLine();}} }

Output

輸出量

Type of arr1: System.Int32[] Type of arr2: System.Single[] Type of arr3: System.String[] arr1 elements... 10 20 30 40 50 arr2 elements... 10 20.1 30.2 40.3 50.4 arr3 elements... Manju Amit Abhi Radib Prem

翻譯自: https://www.includehelp.com/dot-net/implicitly-typed-arrays-in-c-sharp.aspx

c# 無法將類型隱式轉換

總結

以上是生活随笔為你收集整理的c# 无法将类型隐式转换_C#中的隐式类型数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。