First, take a look at these CodeProject articles::
Automated Undo/Redo library based on C# Generics in .NET [
^]
Implementing Object Undo and Redo capabilities in .NET [
^]
Keep in mind that what's shown here ... what a literal interpretation of your question suggests ... is a
stack, a last-in-first-out collection, with a depth of #1. If your goal is to have more than one saved state, consider using the .NET 'Stack data structure.
Using the C# 7 ValueTuple Type [
^] , we can make this easy:
private (int Nmber, string Strg) _previousData;
public (int Nmber, string Strg) PreviousData
{
get { return _previousData; }
}
private (int Nmber, string Strg) _currentData;
public (int Nmber, string Strg) CurrentData
{
set
{
_previousData = (_currentData.Nmber, _currentData.Strg);
_currentData = value;
}
get { return _currentData; }
}
CurrentData = (100, "x");
CurrentData = (200, "y");
var previous = PreviousData;
int prevNum = previous.Nmber;
string prevStrg = previous.Strg;