Free use of the stack semantics available in C ++ / CLI to automatically delete objects. Emulating a Holy C ++ RAII template, an object becomes available even when the code throws an exception. Think about it as the compiler automatically generates a C # using statement. Like this:
using namespace System;
using namespace System::IO;
using namespace System::Security::Cryptography;
using namespace System::Text;
ref class Example {
protected:
String^ GetMD5HashFromFile(String^ fileName)
{
FileStream file(fileName, FileMode::Open);
MD5CryptoServiceProvider md5;
array<Byte>^ retVal = md5.ComputeHash(%file);
return Convert::ToBase64String(retVal);
}
};
source
share