簡體   English   中英

Array []-無法獲得Array [] C#中的值“無法將類型對象隱式轉換為int”

[英]Array[] - Can't get the value in Array[] C# “cannot implicitly convert type object to int”

例如:

Array[] hasil = new Array[1];
hasil[0] = new int[1];
hasil[0].SetValue(99, 0);
int xx = hasil[0].GetValue(0);

為什么我不能獲得hasil[0].GetValue(0)卻說“無法將類型對象隱式轉換為int”

GetValue方法返回object類型,因此您必須將其顯式轉換為int

像這樣

int xx = (int)hasil[0].GetValue(0);

發揮您的價值:

(int)hasil[0].GetValue(0);

當您的編譯器說它不能隱式轉換時,您必須顯式地執行它。 然后添加演員表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM