Argument 1: cannot convert from 'string' to 'int'
时间: 2024-01-14 20:04:33 浏览: 110
This error message usually occurs when you try to assign a string value to an integer variable or pass a string argument to a method that expects an integer argument. To resolve this issue, you need to convert the string value to an integer using the appropriate method.
For example, if you have a string variable named "myString" that contains an integer value, you can convert it to an integer using the Convert.ToInt32() method:
```
string myString = "123";
int myInt = Convert.ToInt32(myString);
```
Alternatively, you can use the int.TryParse() method to convert the string value to an integer safely:
```
string myString = "123";
int myInt;
if (int.TryParse(myString, out myInt))
{
// Conversion successful
}
else
{
// Conversion failed
}
```
In both cases, you will end up with an integer variable that you can use in your code without getting the "cannot convert from 'string' to 'int'" error message.
阅读全文