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?
[Test]
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))
{
searchresult.ShouldNotBeEmpty();
searchresult.ShouldContain("Brittany");
searchresult.Should().Count.NoMoreThan(1);
}
else
{
searchresult.ShouldNotBeEmpty();
searchresult.Equals(num);
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))
{
...
使用
if (int.TryParse(result, out num))
链接地址: http://www.djcxy.com/p/89836.html
上一篇: int.TryParse失败,并在C#中使用Console.ReadLine()
下一篇: TryParse无效参数