开发者

How can you determine if a string has been updated/changed? [closed]

开发者_如何学Go It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜