samedi 26 avril 2014

c# - ne peut pas accéder à la chaîne dans un corps de méthode - Stack Overflow


The code that I have


private bool isValidNumber(string myString)
{
const int VALID_LENGHT = 10;
bool valid = true;
if (myString.Lenght == VALID_LENGHT)
{
foreach (char ch in myString)
{
if (!char.IsDigit(ch))
{
valid = false;
}
}
}
else
{
valid = false;
}
return valid;
}

And the error that I have when I tried to check myString.Lenght



Error 1 'string' does not contain a definition for 'Lenght' and no extension method 'Lenght' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)





It's spelled "Length" not "Lenght".




Problem : Error is straight forward there is no Lenght property for in string class.


Solution : you just need to replace Lenght with Length


Replace This:


if (myString.Lenght == VALID_LENGHT)

With This:


if (myString.Length == VALID_LENGHT)


The code that I have


private bool isValidNumber(string myString)
{
const int VALID_LENGHT = 10;
bool valid = true;
if (myString.Lenght == VALID_LENGHT)
{
foreach (char ch in myString)
{
if (!char.IsDigit(ch))
{
valid = false;
}
}
}
else
{
valid = false;
}
return valid;
}

And the error that I have when I tried to check myString.Lenght



Error 1 'string' does not contain a definition for 'Lenght' and no extension method 'Lenght' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)




It's spelled "Length" not "Lenght".



Problem : Error is straight forward there is no Lenght property for in string class.


Solution : you just need to replace Lenght with Length


Replace This:


if (myString.Lenght == VALID_LENGHT)

With This:


if (myString.Length == VALID_LENGHT)

0 commentaires:

Enregistrer un commentaire