As an implementation note one should keep in mind that dispose (which happens with using) doesn't insure that exceptions cannot be thrown.
Which is fine if you don't mind if an exception occurs on that last closing brace but if you are trying to create a fail safe method then it is inappropriate.
One should also consider what the impact is to the business functionality. So for example in the given sample code if one successfully read the file but then the close fails (in the dispose) then does the application (business functionality) really care?
As others have said, the code you've posted will work as expected.
However, you can avoid the try..catch block by using the TryParse methods. You should also check the result of line.Split(';') to avoid an IndexOutOfRangeException, check that the second field is a valid Enum value, and check that the dictionary doesn't already contain the key:
string fields = line.Split(';');
if (fields.Length < 5) returnfalse;
// TODO: Give these variables proper names:
int f1, f3, f4;
if (!long.TryParse(fields, out f0)) returnfalse;
if (!int.TryParse(fields, out f1)) returnfalse;
if (!int.TryParse(fields, out f3)) returnfalse;
if (!int.TryParse(fields, out f4)) returnfalse;
// If the dictionary already contains the key, the Add method throws an ArgumentException:
if (prodFileIndexDic.ContainsKey(f0)) returnfalse;
// Any integer can be cast to any enum without an exception;
// you probably wany to check that it's valid first:
if (!Enum.IsDefined(typeof(ProdKategoriEnum), f1)) returnfalse;
prodList.Add(new Produkt(f0, (ProdKategoriEnum)f1, fields, f3, f4));
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I have an application in C# which uses a SQLite database. In this database I have a table where I inserted a value encrypted with sha1, via sql query. Te problem is that I want to select that data and use it like:
cmd.CommandText = "Select * from accounts where (username=@username and password=sha1(@password));";
cmd.CommandText = "Select * from accounts where (username=@username and password=@password);";
But from what I heard, I can't use sha1 like this, I have to use a function like this one, but it doesn't work: