Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
C#
string data = DataTextBox.Text; 
        List<string> gradeString = new List<string>     
        (data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));
        List<int> intList = gradeString.ConvertAll<int>(Convert.ToInt32);
        intList.Sort();
        string[] text = new string[100];</int></int></string></string>
Posted
Updated 8-Oct-15 8:02am
v2
Comments
ZurdoDev 8-Oct-15 13:44pm    
Where are you stuck.

It appears to take rows from a textbox value and sort them.

1 solution

First it makes a copy of the text in the DataTextBox.Text property.
C#
string data = DataTextBox.Text

Then instantiates a new List<string>, with the data returned by the Split call.
C#
List<string> gradeString = new List<string>(data.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));</string></string>

The (data.Split(new string[] { "\r\n" }, StringSplitOption.RemoveEmptyEntries))
actuall searches data for "\r\n" and adds anything to the left to an array (except emtpy strings, then skips to the next "\r\n".
The List<string> is then populated with the contents of the array since it is an IEnumerable<t>.

So, to break it down further..
C#
string test = "Look at how\r\nthis works!";

// This it how the data.Split part works.
string[] split = test.Split(new string[] { "\r\n" });

// string[0] == "Look at how"
// string[1] == "this works!"

List<string> testSplit = new List<string>(split);
</string></string>


The next portion does a convert all on the list, given the generic type and a converter.

C#
<int></int>
is the generic type and
C#
Convert.ToInt32
is the converter.
This basically says, i want the contents of gradeString to be converted to a List if int types.

C#
intList.Sort()
sorts the list in ascending order.
 
Share this 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