在c#中使用foreach

在c#中使用foreach

问题描述:

嗨frens,





我有一串数组

ex:string [] abc = new string [] {3,2,1};



如何使用foreach获得值3









如果我使用



foreach(int x in abc)

{



}



x返回51,相当于ascii 3但我需要3 ..

请帮帮我...





提前感谢

darshan

Hi frens,


I have a string of arrays
ex :string[] abc= new string[] { "3", "2", "1" };

how can i get the value 3 using foreach




if i use

foreach(int x in abc )
{

}

x is returning 51 which is ascii equivalent of 3 but i need 3 ..
please help me...


thanks in advance
darshan

string[] abc = new string[] { "3", "2", "1" };
            foreach (string s in abc)
            {
                //Your code here
            }



而不是 int 在foreach中使用 string 。我已经尝试了上面的代码,它的工作正常。


Instead of int in foreach use string. I have tried above code, its working fine.


我有一串数组

I have a string of arrays
string[] abc= new string[] { "3", "2", "1" };

foreach(string x in abc )
{
Console.WriteLins(x);
}


hi,



使用此: -



Use this :-
string[] abc = new string[] { "3", "2", "1" };

            foreach (string x in abc)
            {
                Console.Write(Convert.ToInt32(x));
            }