'string' does not contain a definition for 'IsInt' and no extension method 'IsInt' accepting a first argument of type 'string' could be found

StackOverflow https://stackoverflow.com/questions/23472695

  •  15-07-2023
  •  | 
  •  

Вопрос

The isInt doesn't seem to work when put into a class file and i don't understand why. When used within my code it works fine it's just it doesn't like x.IsInt when i moved it into a class file?

public static Boolean Integervalid(string x)
{

    bool i = false;

    if (x.IsInt())
    {
        i = true;
    }

    return i;
}
Это было полезно?

Решение

That's probably because IsInt() is an extension method that's in System.Web.WebPages.dll, and you don't have a reference to it.

See MSDN

Другие советы

You need add the following assembly: System.Web.WebPages (in System.Web.WebPages.dll)

see: http://msdn.microsoft.com/de-de/library/system.web.webpages.stringextensions.isint(v=vs.111).aspx

I suggest to use TryParse to be more independent from the WebPages.dll. TryParse is included in mscorlib

int number;
bool result = Int32.TryParse(value, out number);

see: http://msdn.microsoft.com/de-de/library/f02979c7(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top