Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 27-Dec-12 1:08am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Comments
darshan559 at 27-Dec-12 7:52am
   
thank u so much..it worked
Vani Kulkarni at 27-Dec-12 7:58am
   
Great! :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I have a string of arrays
string[] abc= new string[] { "3", "2", "1" };
 
foreach(string x in abc )
{
Console.WriteLins(x);
}
  Permalink  
v2
Comments
darshan559 at 27-Dec-12 7:52am
   
thank u so much..it worked
Oleksandr Kulchytskyi at 27-Dec-12 7:55am
   
So if you mind,please rate our answer ;)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

hi,
 
Use this :-
string[] abc = new string[] { "3", "2", "1" };
 
            foreach (string x in abc)
            {
                Console.Write(Convert.ToInt32(x));
            }
  Permalink  
Comments
darshan559 at 27-Dec-12 7:52am
   
thank u so much..it worked

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

  Print Answers RSS
0 OriginalGriff 6,656
1 Sergey Alexandrovich Kryukov 6,490
2 CPallini 5,310
3 George Jonsson 3,584
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140921.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100