Geek-o-Philiac

Sunday, September 17, 2006

C# File Reading

In writing my tile map class for a map editor/Parodica, I ran into a nifty little quirk of .NET: there's no clean way to read numbers from files.

In C++, the process is pretty painless. ifstream is designed in such a way that it will seemlessly parse strings, ints, floats, or even your own user defined types. In C#, the process is not so straight forward. First you have to read the file in as a string and then you have to tokenize it and then you have to convert those string tokens into the appropriate data types. Not only is this less efficient, but it's also just plain ugly.

I can't imagine why there was such an oversight. My only guess is that the .NET language designers envisioned a world where everyone was using XML to store data. But I'll contend - to my grave - that XML is not the best option here since it is not really suitable for storing large arrays of data and it's overkill since my data is in no way heirarchical.

0 Comments:

Post a Comment

<< Home