How to read and write the file for sorting the string names in source file and want to write it on target file in C# using Windows Form Application ?
* The Source file(*.txt) was already created and it contains
Hockey
BAsketball
Football
Tennis
Cricket
* I want to read a source file using streamwriter and also sort the strings in alphabetically
* That sorted string values write on the another target file(*.txt) using streamwriter
plz help this.....
Thanks !!
Iftikar HussainPosted Jul 19, 2013, 6:47 AM
The role of IComparable is to provide a method of comparing two objects of a particular type. This is necessary if you want to provide any ordering capability for your object.
Regards,
Iftikar
VijayPosted Jul 19, 2013, 6:05 AM
Plz let me know one thing....
Instead of using
if (String.Compare(data[j- 1], data[j]) > 0)
string temp = data[i - 1];
You used....
if (((IComparable)data[j - 1]).CompareTo(data[j]) > 0)
what is use of IComparable and why you used object for temp var ?
difference between IComparable and String.Compare ?
Iftikar HussainPosted Jul 19, 2013, 5:30 AM
Regards,
Iftikar
VijayPosted Jul 19, 2013, 5:14 AM
I tried that code like....
When i browse and select that source file , the file was selected. After that i want to sort which was i selected file. After that i want write on another file which was sorted strings.
Iftikar HussainPosted Jul 19, 2013, 1:59 AM
Regards,
Iftikar
VijayPosted Jul 19, 2013, 1:50 AM
Iftikar HussainPosted Jul 19, 2013, 1:22 AM
Regards,
Iftikar
VijayPosted Jul 19, 2013, 1:16 AM
thank u very much Iftikar...
Is this possible to sort without using any sorting methods.....
Iftikar HussainPosted Jul 19, 2013, 12:56 AM
Try like this
Regards,
Iftikar