I haven't tried to run your class, so my comments are merely style related. [smile]
First and foremost is the naming convention; I tend to write code that follows the .NET conventions - at least for public members. In this case, then, that'd be:
public bool ReadFile(string filename)
I'd also make public members properties (even if they don't do anything exceptional), so my struct would be:
struct PropVar{ private string name; public string Name { get { return this.name; } set { this.name = value; } } public string value; public string Value { get { return this.value; } set { this.value = value; } } public override string ToString() { return string.Format("{0}={1}", this.Name, this.Value); }}
I would also nest PropVar inside the class itself, as it's pretty meaningless outside the context of the class.
I like being able to just Console.WriteLine() a variable, hence the ToString() method.
Really, though, I'd prefer to use .NET's built-in types for this;
KeyValuePair<T, T> is provided for us already. In the same vein I'd probably prefer to return a
Dictionary<T, T> of key/value pairs. In this specific instance there are specialised classes - such as the
StringDictionary - that would be more appropriate.
Furthermore, I'd rather the class automatically read the file if I passed it the filename (or a stream) in the constructor.
The exception handling is rather strange; if something goes wrong throw the exception and let the application using your class handle it. Do not use return codes to check the status.
You could, I suppose, write an extra method that doesn't throw any exceptions (or display any message boxes) with the name TryReadFile if there is a strong chance of dodgy input.
if(strings.Length < 2 || strings.Length > 2);// Could be (slightly more intuitively):if(strings.Length != 2);
Take a look at the
using statement for your file streams and readers. If you must wrap an exception handler around your code, don't forget a finally block to clean up your open files!
I hope I don't come across as rude, that is not my intention.