none
how sorting x(int) at txt files in c# RRS feed

Yanıtlar

  • Without a sample of the text file content it is shooting in the dark. We would just imagine that you have a text file where each line has an integer representation and you want to sort the values, something like:

    123
    747
    1
    39
    4

    ? If so it is as simple as it might be without error checking:

    string fileName = @"c:\My Folder\myTextFile.txt";
    
    var sorted = File.ReadAllLines(fileName)
                 .Select( line => int.Parse(line) )
                 .OrderBy( i => i );

    10 Kasım 2015 Salı 15:28
    Yanıtlayıcı

Tüm Yanıtlar

  • Bunu nerede yapıcaksınız dosya içinde mi gridde mi yoksa başka bir bileşende mi?


    kdrgny@outlook.com

    10 Kasım 2015 Salı 15:04
  • Without a sample of the text file content it is shooting in the dark. We would just imagine that you have a text file where each line has an integer representation and you want to sort the values, something like:

    123
    747
    1
    39
    4

    ? If so it is as simple as it might be without error checking:

    string fileName = @"c:\My Folder\myTextFile.txt";
    
    var sorted = File.ReadAllLines(fileName)
                 .Select( line => int.Parse(line) )
                 .OrderBy( i => i );

    10 Kasım 2015 Salı 15:28
    Yanıtlayıcı