Comparing strings with objects in C # / XNA

I have an XML file that is split using the "|" pipe. I have code in a question class that breaks down the Elements XML files as such.

 List<string> questionComponents = newquestionString.Split('|').ToList<string>();

        questionString = questionComponents[0];
        apple = questionComponents[1];
        pear = questionComponents[2];
        orange = questionComponents[3];

        correctAnswer = Int32.Parse(questionComponents[4]);

I want to compare these components with the objects that are created in my Game1 class (three fruits - apple, pear, orange). So how do I do this?

A friend helped me get this far. I have no idea how to do this, and after searching Google with no luck, I led to asking you to be wonderful people.

Thanks in advance: D

EDIT: clear things ...

I have three objects called apple, pear and orange, and I want to associate these objects with the lines that are shown in the XML file for each component of the lines. The question line displays the question, [1] answer 1, [2] answer 2, [3] answer [3].

, .

+3
3

, - Orange, - Pear - Apple, override ToString.

Fruit Answer , ToString.

: , , Name Answer; :

if(object.Answer == questionComponent)
//do stuff

ToString . ( ) - Ints "42", bools "true" "false". .

+2

, , , , - - , ? Dictionary , :

Fruit apple = new Apple();
Fruit orange = new Orange();

Dictionary<string,Fruit> map = new Dictionary<string,Fruit>();
map["apple"] = apple;
map["orange"] = orange;

/:

string input = ...
Fruit result;
if(map.TryGetValue(input, out result)) {
  // `fruit` now holds the fruit object the user selected.
} else {
  // User input did not correspond to a known fruit.
}

, .

+1

, , Enums, , ?

public enum AnswerType
{
  Apple,
  Pear,
  Banana
}

( enum int ) , , , eated fruit id, .

0
source

All Articles