-4

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#

Community
  • 1
  • 1
walter
  • 843
  • 2
  • 14
  • 35

3 Answers3

4

Perhaps you could try making a hash of the 2 strings and compare those...

I hope this help...

Nigel Findlater
  • 1,684
  • 14
  • 34
2

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;
        }
    }
}
Rob
  • 26,989
  • 16
  • 82
  • 98
1

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.