user3314640 user3314640 - 11 months ago 88
C# Question

TryParse Invalid Arguments

I am trying to run a NUnit test searching for numbers within a string. I'm using TryParse but it gave me a this error: Error1: The best overloaded method match for 'int.TryParse(string, out int)' has some invalid arguments.

Could you guys tell me what I'm doing wrong?

public void ThenSearchForBrittanyShouldFindOneUser()
var searchresult = LuceneFullTextSearch.SuggestSimilar("brit123", 1).ToArray();

int num = 0;
foreach (var result in searchresult)

if (result = int.TryParse(searchresult, out num))

Answer Source

searchresult is an array, not a string; you want result there instead.

Also, you can't have an assignment in an if conditional, so your syntax is wrong anyway. TryParse already returns a bool, so you should try:

    if (int.TryParse(result, out num))