2

first time poster so forgive me if my formatting is off or anything :)

I'm working on my game engine in C# using XNA but when I check the name of a new node against existing nodes, the Assert fires off unpredictably even when there is no matching name in the list. Here is the code I'm referring too:

    public void CheckNameIsUnique(string cName)
    {
        for (int i = 0; i < m_aNodeList.Count; ++i)
        {
            Debug.Assert(m_aNodeList[i].GetName().Equals(cName),
                "USE OF NON-UNIQUE NAME: " + cName);
        }
    }

The assert will fire off -for example- when checking, "box1" and the only node in the list has the name "RootNode".

I get the same unpredictable results using: string == string and string.CompareTo(string) > 0

Any ideas? =\

2 Answers 2

8

Assert is supposed to make sure the condition is TRUE. If it's false the assert will fail. What you want is to assert that it's NOT equal. use != and it should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

I was in a hurry when I made my last comment, so to elaborate a little now, I was feeling VERY stupid when you pointed out my miss use of Assert.. As I had been using it successfully all day >.> I guess my brain just shut off for a while there haha. Again, many thanks.
I guess taking breaks at the right time is also a skill we need to learn :). Glad it helped you out.
3

The assertion fires if the condition is false. You have your conditional backwards. See here:

http://msdn.microsoft.com/en-us/library/e63efys0.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.