The problem: user enters an answer (a,b,c,d). the program should match from database and get the exact full answer.
Example:
What is 9 + 1?
a. 9
b. 10
c. 5
d. 21
When user writes (b) the program should get the answer which is (10)
here is what i did:
private string Answer(string question, string answer)
{
string userans = null;
try
{
if (question != null || answer != null)
{
string[] inputSplit = question.ToString().Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < inputSplit.Length; i++)
{
if (inputSplit[i].Contains(answer + "."))
{
userans = inputSplit[i].Split('.')[1];
return userans;
}
else
{
userans = null;
}
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return userans;
}
The question is: How i can avoid using Loop and extract the same result?. or is there a better way to do it?
ToStringonquestion? It's already astring.