如何将对象转换为int类型?
这是我的代码
DataSnapshot snapshot = task.Result;
foreach (DataSnapshot child in snapshot.Children)
{
if (child.Key == "myAge")
{
MyAgeInput.value = int.Parse(child.Value);
}
}
这是我的错误错误CS1503:参数1:无法从'对象'转换为'字符串'
我看到语法是c#。
试试这个:
DataSnapshot snapshot = task.Result;
foreach (DataSnapshot child in snapshot.Children)
{
if (string.Equals(child.Key, "myAge")
{
int parsedValue;
int.TryParse(child.Value?.ToString(), out parsedValue);
MyAgeInput.value = parsedValue;
}
}
提前提示:请指定问题标签和编程语言的权利。