Hi
I am writing a program using the SortedList class . Please contain laughter
if i am doing something stupid.,
I am using a struct as the value part to store a range of information
against a unique key (see below)
I was hoping that when i found the entry again, i could get a reference back
to my struct and update the data.
Things don't seem to be working as i expected. If this was C or C++ i would
know how to handle the pointers and casting.
Is my approach valid ? Is casting from struct to object and vice versa OK
?
FileRecord Entry;
object nObj;
........
.....other code here...
try
{
if (!FileInfoEntries.ContainsKey(Filename))
{
// First use of key part
Entry = new FileRecord();
Entry.nOpenCount = 0;
Entry.nReadCount = 0;
Entry.nWriteCount = nFileLine;
Entry.bMonitorMe = true;
Entry.nAverageReadLength = 0;
FileInfoEntries.Add(Filename, (object)Entry);
}
else
{
// repeat of key part
nIndex = FileInfoEntries.IndexOfKey(Filename);
nObj = FileInfoEntries.GetByIndex(nIndex);
Entry = (FileRecord) nObj;
}
}
.... below here Entry.xxx is updated
Thanks in advance (struct is below)
===============================================
public struct FileRecord
{
public Boolean bMonitorMe;
public int nOpenCount;
public int nReadCount;
public int nWriteCount;
public int nAverageReadLength;
public int nLastOpenTime;
public int nLastOpenMode;
public int nLastIOOperationTime;
public Boolean bStartupFile;
public Boolean bRuntimeFile;
public Boolean bShutdownFile;
};