Is there a way to implement a class (without using unsafe pointers)
that holds a reference to a variable along with its original value,
then on destruction sets the referred-to variable back to the original
value? Some kind of DataBackup<Tclass, used as follows:
int x = 2;
using (DataBackup<intbackup = new DataBackup<int>(x))
{
//... do processing with x, presumably assigning it a temporarily
different value, like
x = 3;
} // on Dispose(), x gets reset back to its original value, 2
class DataBackup<T: IDisposable {
//??? how to do it
}
This is possible in other languages, but without reference-to-
reference it would seem to be harder in C#. Is there a neat way to do
it?