How can you determine if a string has been updated/changed? [closed]
I cannot keep the original string in memory because it is too big.
var source = "some text";
var cache = source;
source = "some other text";
if(source != cache){
// Updated, do something
}
Any idea how to find if the source string was updated/changed without comparing source and cache?
Updated, i have a found linked question Example to use a hashcode to detect if an element of a List<string> has changed C#
Perhaps you could try making a hash of the 2 strings and compare those...
I hope this help...
Have you tried using a custom getter?
class SomeClass
{
private bool m_MyStringUpdated;
private String m_MyString;
public String myString
{
get
{
return m_MyString;
}
set
{
m_MyString = value;
m_MyStringUpdated = true;
}
}
}
If you can't keep the string a variable cache, then I'd say the best route is to utilize a collection with a key/value pair. Something like Dictionary<datetime, string>
where the key would be the last updated datetime stamp and string is the stored string.
Or you could use Dictionary<bool, string>
where the key is a boolean of whether or not it is updated (true/false). You will just need to remember to reset it to false
after you have handled the instance of an updated string value.
精彩评论