You would do something like the following. I did notice your original code had an issue with the for loop not iterating over "Length / 2". So, that may have given you some of your problems as well. Plus, with this code, you'll want to verify the following:
-End of file case is handled properly.
-Byte to ushort conversion is valid for your case (ie. little endian vs. big endian) - I believe it is, but double check.
private Dictionary<string, List<ushort>> loadDesignFiles(string ext)
{
Dictionary<string, List<ushort>> dctAllGroups;
List<ushort> lstWords;
byte[] wordbuf;
dctAllGroups = new Dictionary<string, List<ushort>>();
wordbuf = new byte[2];
foreach (string strFileName in Directory.GetFiles(userDirectory, "*." + ext))
{
dctAllGroups[strFileName] = lstWords = new List<ushort>();
using (FileStream inFile = File.OpenRead(strFileName))
{
while (inFile.Read(wordbuf, 0, 2) == 2)
{
lstWords.Add(BitConverter.ToUInt16(wordbuf, 0));
}
}
}
if (dctAllGroups.Count == 0)
MessageBox.Show("No Design Files Found", "Warning");
else
MessageBox.Show("Loaded " + dctAllGroups.Count + " Design Files", "Note");
return dctAllGroups;
}
The more you develop and read other people's code, the better you'll get. Just keep in there.