sr.ReadToEnd().Split('\n') is horribly inefficient and wrong (on windows CrLf files).
Why not simply use sr.ReadLine? Convert.ToInt32 and family have a load of assumptions about current culture (locale) and will not only break, but silently interpret into the _wrong_ values if you don't specificly make sure what format is being parsed.
Other mechanisms (e.g. Xml) nicely prevent this kind of mess, and you can always use .NET serialization with formatters if you need bleeding performance
@wwwsant This was an extension onto my previous saving out into a text file code tutorial. It wasn't meant as anything super efficient, just talking about things out there.
Problem with sr.ReadLine, is you don't have as exact control over what you are reading when. Now, I don't thing it was a problem here, but you get my point.
System.Convert.ToInt32 is regional, if in your country, you use commas for decimals, it will work. Only problem I see with that, is if you have english code....
@wwwsant But again, this wasn't supposed to be anything like, "Oh, this is the best way to do it!" it was, "Oh, well, before we did it this long way, this time lets do it the short and much easier route.
hey guys maybe i miss somthing but does anyone know how use this to write a Console.Writeline into a txt file.
messi996 10 months ago
@messi996 You have to open up a steam and do Stream.writeline essentially
steamisM50 10 months ago
sr.ReadToEnd().Split('\n') is horribly inefficient and wrong (on windows CrLf files).
Why not simply use sr.ReadLine? Convert.ToInt32 and family have a load of assumptions about current culture (locale) and will not only break, but silently interpret into the _wrong_ values if you don't specificly make sure what format is being parsed.
Other mechanisms (e.g. Xml) nicely prevent this kind of mess, and you can always use .NET serialization with formatters if you need bleeding performance
wwwsant 1 year ago
@wwwsant This was an extension onto my previous saving out into a text file code tutorial. It wasn't meant as anything super efficient, just talking about things out there.
Problem with sr.ReadLine, is you don't have as exact control over what you are reading when. Now, I don't thing it was a problem here, but you get my point.
System.Convert.ToInt32 is regional, if in your country, you use commas for decimals, it will work. Only problem I see with that, is if you have english code....
steamisM50 1 year ago
@wwwsant But again, this wasn't supposed to be anything like, "Oh, this is the best way to do it!" it was, "Oh, well, before we did it this long way, this time lets do it the short and much easier route.
steamisM50 1 year ago