5
Well, I’m starting now in C#, but I already have a great experience with PHP and I know more or less Python
.
And the means that I use to appeal is to do something that I found difficult to do in a language that I know in a language that I know nothing about.
I asked here how to count the lines of a large file in PHP, because it is something that is not so simple to do in the language, does not have a specific function for it, I have to do maneuvers.
Now that I’m learning C#
, i wonder how do I know how many lines has a large file.
But I would like each function used to be explained, because I don’t know much about C# yet.
I want to read a JSON
of 6.6MB
here from my machine and know how many lines it has through the C#.
How can I do that?
Well, that’s better that PHP then +1
– Wallace Maxters
I just think it’s important to remember that
Count
forces the reading of the entire file, which is not very clear in the code, but basically the only way to know how many lines a file has is to go reading and counting how many lines there are in it.– Leandro Godoy Rosa
@Leandrogodoyrosa since this reading does not load all the lines into the memory, no problem. The goal really is to read a large file, I believe the answer meets
– Wallace Maxters
If your goal is to read the entire file, doing this "before" count is silly because you will end up reading the file twice. What is the purpose of knowing the number of lines? Would it be to use in a progress bar (that is, estimating the completed percentage)? If it is, I would suggest "estimating" the number of lines based on the file size (it averages 80 characters per line, for example). Or, more precisely, use the number of characters read. :)
– Luiz Vieira
Actually the question does not apply to a specific context @Luizvieira. It was a question from AP.
– Jéf Bueno
Sorry, I ended up posting in your reply unintentionally. But my comment is precisely for AP. :)
– Luiz Vieira
I had noticed :P
– Jéf Bueno