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 array
Console.WriteLine("Type of arr1: " + arr1.GetType());
Console.WriteLine("Type of arr2: " + arr2.GetType());
Console.WriteLine("Type of arr3: " + arr3.GetType());
//printing the elements
Console.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 exit
Console.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# 無法將類型隱式轉換

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/377885.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/377885.shtml
英文地址,請注明出處:http://en.pswp.cn/news/377885.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

一、信用卡卡號識別

一、思路分析 大體思路:首先拿到一張銀行卡,我們得有銀行卡號數字的0-9樣式的模板,然后再通過不同數字的輪廓的外接矩形來進行匹配,最終識別出銀行卡號所對應的數字。 銀行卡數字模板: 銀行卡信息: 拿到…

bootstrap網格系統_如何使用Bootstrap網格系統?

bootstrap網格系統In the last article, we learned how to create a simple page of Bootstrap? Now, we will learn what is "Grid System" in Bootstrap and how we can use or implement it in our bootstrap page? As you know bootstrap is a mobile-friendl…

有關WriteableBitmap和BitmapImage之間的相互轉換

對于WP7中圖形處理有關WriteableBitmap和BitmapImage之間的相互轉換,給大家幾個簡單實用的方法。一、WriteableBitmap轉為BitmapImage對象var bi new BitmapImage(); bi.SetSource(wb.ToImage().ToStream()); //其中wb是WriteableBitmap對象。 二、BitmapImage轉為…

回溯法初步

本文為參考公眾號所做的筆記。 代碼隨想錄原文 回溯法本質是窮舉,窮舉所有可能,然后選出我們想要的答案,所以它并不是一個高效的算法。但是由于有些問題本身能用暴力搜出來就不錯了,所以回溯法也有很多的應用。 回溯法解決的問題…

QEMU中smp,socket,cores,threads幾個參數的理解

在用QEMU創建KVM guest的時候,為了指定guest cpu資源,用到了-smp, -sockets, -cores, -threads幾個參數, #/usr/bin/qemu-system-x86_64 -name pqsfc085 -enable-kvm -m 2048 -smp 2,sockets2,cores1,threads1 \ -boot ordernc,onced \ -hda …

二、文檔掃描OCR

一、思路分析 首先,拿到一張文檔,我們需要對文檔進行預處理操作,再進行輪廓檢測,因為就算拿到文檔輪廓,但是這些輪廓也有可能是歪歪扭扭的,這時候需要通過一系列的透視變換操作,將文檔擺正。通…

ruby hash方法_Ruby中帶有示例的Hash.select方法

ruby hash方法哈希選擇方法 (Hash.select Method) In this article, we will study about Hash.select Method. The working of this method can be predicted with the help of its name but it is not as simple as it seems. Well, we will understand this method with the…

leetcode 77. 組合 思考分析

目錄1、題目2、回溯法思路3、參考其他思路,更深入了解這個問題4、剪枝優化可能需要回顧到的知識文章:1、常用算法總結(窮舉法、貪心算法、遞歸與分治算法、回溯算法、數值概率算法)2、回溯法初步刪除vector容器中的對象元素的三種方法:pop_back, erase與…

ASP 調用dll(VB)及封裝dll實例

ASP調用dll及封裝dll實例,封裝為dll可以提供運行效率,加密代碼。 打開VB6,新建ActiveX DLL 2、在工程引用中加入Microsoft Active Server Pages Object Library選擇 3、填加代碼如下Code Start 聲明部分 Private MyScriptingContext As Scrip…

三、全景拼接

一、項目所涉及到的一些知識點 Ⅰ,BF(Brute-Force)暴力匹配:把兩張圖像的特征點全部給算出來,然后使用歸一化的歐氏距離比較這兩張圖像上特征點之間的大小關系,越小越相似。 SIFT算法 import cv2 import numpy as np import ma…

找回自建SVN密碼

自建了一個SVN Repo自己用。重裝系統之后密碼忘了。 經過了漫長的Google過程,才知道Repo中的密碼居然是明文保存的。 在yourRepoDir/conf/svnserve.conf下的password-db處設置,通常是yourRepoDir/conf/passwd文件。 打開passwd文件,就是明文保…

ruby hash方法_Ruby中帶有示例的Hash.invert方法

ruby hash方法Hash.invert方法 (Hash.invert Method) In this article, we will study about Hash.invert Method. The working of this method can be predicted with the help of its name but it is not as simple as it seems. Well, we will understand this method with …

leetcode 216. 組合總和 III 思考分析

可能需要回顧的文章; leetcode 77. 組合 思考分析 1、題目 找出所有相加之和為 n 的 k 個數的組合。組合中只允許含有 1 - 9 的正整數,并且每種組合中不存在重復的數字。 說明: 所有數字都是正整數。 解集不能包含重復的組合。 2、遞歸 這一題和之前…

【Unity】Update()和FixedUpdate()

Update()每幀調用,FixedUpdate()以指定頻率被調用。可以在 Edit -> project settings -> Time -> Fixed Timestep 中設定該頻率。轉載于:https://www.cnblogs.com/xiayong123/p/3717002.html

約束執行區域(CER)

受約束的執行區域 (CER) 是創作可靠托管代碼的機制的一部分。CER 定義一個區域,在該區域中公共語言運行庫 (CLR) 會受到約束,不能引發可使區域中的代碼無法完全執行的帶外異常。在該區域中,用戶代碼受到約束,不能執行會導致引發帶…

python 抓取網頁鏈接_從Python中的網頁抓取鏈接

python 抓取網頁鏈接Prerequisite: 先決條件: Urllib3: It is a powerful, sanity-friendly HTTP client for Python with having many features like thread safety, client-side SSL/TSL verification, connection pooling, file uploading with multipart encod…

四、模擬英語四六級答題卡識別閱卷評分

一、思路分析 首先拿到答題卡照片的時候,需要對照片進行一系列預處理操作,通過透視變換將圖像擺正方便后續的操作。每一道題五個選項,有五道題,通過字典存放準確答案。沒有依次對答題卡進行輪廓檢測,這里采用的是正方…

leetcode 17. 電話號碼的字母組合 思考分析

題目 給定一個僅包含數字 2-9 的字符串,返回所有它能表示的字母組合。 給出數字到字母的映射如下(與電話按鍵相同)。注意 1 不對應任何字母。 思考與遞歸程序 解空間樹的寬度是輸入數字對應的字符的個數,深度是輸入的數字的個數…

Blockquotes,引用,html里面,經常用到的一個!

blockquote元素的使用已經非常多樣化&#xff0c;但語義上它只適用于一件事–標記了一段你的網頁被引用從另一來源。這意味著&#xff0c;如果你想讓那些花俏的引文&#xff0c;<blockquote>是不是你應該使用元素。讓我們看一看如何你應該使用此元素&#xff1a; <art…

仔細分析了下這7行,貌似時間復雜度,空間復雜度都不大,為嘛就是執行效率這么低?...

for(Girl girl Girls.first(); !myGirlFriend.like(me); girl Girls.next()){if(!girl.hasBoyFriend(now) && i.like(girl)) { GirlFriend myGirlFriend (GirlFriend)girl; }} 轉載于:https://www.cnblogs.com/naran/archive/2011/12/28/2305467.html…