![](/img/trans.png)
[英]how can i retrieve the json data from url and store it in an array..?
[英]How can I retrieve an array from a stack
我想在正在開發的項目中實現堆棧,因為我是一個初學者,所以以前沒有使用過堆棧。 我只是覺得他們會解決問題。 我對它們的工作方式有一個大致的了解,但是在嘗試檢索id已推送到堆棧中的數組時遇到了麻煩,正在返回
static void Main(string[] args)
{
int G;
int [] A=new int [2];
Stack st = new Stack();
for (G = 0; G < 5; G++)
{
A[0] = G;
A[1] = G;
st.Push(A);
}
foreach (Object obj in st)
{
Console.WriteLine(obj);
}
Console.ReadKey();
}
我沒有得到一組數組,而是得到了System.Int32[]
-如何返回數組的內容
問題是您正在使用
Console.WriteLine(obj);
將對象作為參數傳遞。 此方法需要一個字符串作為輸入,因此,您應該先將數組轉換為字符串。
這個問題可能會對您有所幫助:將int數組轉換為字符串
這應該工作:
static void Main(string[] args)
{
int G;
int [] A=new int [2];
Stack st = new Stack();
for (G = 0; G < 5; G++)
{
A[0] = G;
A[1] = G;
st.Push(A);
}
foreach (Object obj in st)
{
Console.WriteLine(string.Join("", (int[])obj));
}
Console.ReadKey();
}
另外,您應該注意到在堆棧中將相同的數組壓入了五次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.