My Faq on "hashtable lookups for struct types" is published at http://blogs.msdn.com/CSharpFaq
Check out
http://blogs.msdn.com/csharpfaq/archive/2006/03/20/556192.aspx
for a FAQ on Hashtable lookup for value types.
Check out
http://blogs.msdn.com/csharpfaq/archive/2006/03/20/556192.aspx
for a FAQ on Hashtable lookup for value types.
Many a times, we use the catch block inside the try catch block for our clean up code.
Something like
try
{
// Do something
}
catch
{
// work failed, clean up code here
}
Rather than the above approach of using the catch block, it would be nicer to use the finally block, something like
bool workSuccessful = false;
try
{
// do some work
workSuccessful = true;
}
finally
{
if(!workSuccessfull)
{
// cleanup code here.
}
}
There is elegance in the latter method and I would certainly recommend that approach, if you cannot use “using“. See below for details.
PS: Use this approach only if better alternatives are not available. One of the automatic cleanup approaches available with C# is the using construct.
Something like,
using (TextReader tr = new StreamReader(“FileName”))
{
// do my work here.
}
The “using” construct automatically clean up the unmanaged resource (TextReader) once the block has completed execution.
In the event that you cannot use “using“, the try-finally approach would be the best way.
Here is a C# code snippet to determine if a particular DLL is registered or not.
[DllImport(“kernel32”)]
public extern static int LoadLibrary(string lpLibFileName);
[DllImport(“kernel32”)]
public extern static bool FreeLibrary(int hLibModule);
public bool IsDllRegistered(string DllName)
{
int libId = LoadLibrary(DllName);
if (libId>0) FreeLibrary(libId);
return (libId>0);
}
Source: http://blogs.msdn.com/asanto
Want to learn more about Visual Studio 2005.
MSDN magazine folks have come up with a new issue dedicated solely to the new IDE.
Check it out online at http://msdn.microsoft.com/msdnmag/issues/06/00/default.aspx