[英]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.