May 22
Here is one way to parse and sort a string with comma-delimited numbers:
string input = "1,9,3,4,3,9,1,5,6,78,"; string[] stringArray = input.Split( new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries ); int length = stringArray.Length; int[] intArray = new int[length]; for (int i = 0; i < length; i++) { try { intArray[i] = Convert.ToInt32( stringArray[i] ); } catch (Exception) { // ignore } } Array.Sort( intArray );
Note how you must convert the numeric strings to integers BEFORE sorting. Otherwise you will end up with the sort order 6, 78, 9, for example. The Convert.ToInt32 method is enclosed in a try-catch block in case the numeric string does not contain a number, in which case it will default to 0.
Uff I was way off.
Thanks
If used Int32.TryParse, then no need of Try catch
I realy need it.tnx alot
Hi Guys
I Want c# program that compile the for statement
for example if we write the for statement correctly
for(int i=0;i>x;i++)
that console”accept” else
far(iat i&0;i<0;i**) "not accept"
please i want it in main program i don't want it in methods
MAIN PROGRAM