Click here to Skip to main content
16,020,990 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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

Instead of int in foreach use string. I have tried above code, its working fine.
 
Share this answer
 
Comments
darshan559 27-Dec-12 7:52am    
thank u so much..it worked
Vani Kulkarni 27-Dec-12 7:58am    
Great! :)
hi,

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

            foreach (string x in abc)
            {
                Console.Write(Convert.ToInt32(x));
            }
 
Share this answer
 
Comments
darshan559 27-Dec-12 7:52am    
thank u so much..it worked
I have a string of arrays
C#
string[] abc= new string[] { "3", "2", "1" };

foreach(string x in abc )
{
Console.WriteLins(x);
}
 
Share this answer
 
v2
Comments
darshan559 27-Dec-12 7:52am    
thank u so much..it worked
Oleksandr Kulchytskyi 27-Dec-12 7:55am    
So if you mind,please rate our answer ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900