[英]InvalidOperationException was unhandled c#
Anyone here knows about c# Please help me, i can not find my error in here. 这里的任何人都知道c#请帮助我,我在这里找不到我的错误。
if (weather != "Data not found")
{
richTextBoxWeatherDetails.Clear();
XmlSerializer result = new XmlSerializer(typeof(Weather.CurrentWeather));
var w = (Weather.CurrentWeather)result.Deserialize(new StringReader(weather));
for (int i = 0; i < w.ItemsElementName.Length; i++)
{
richTextBoxWeatherDetails.Text += w.ItemsElementName[i] + ": " +w.Items[i] + "\r\n";
}
}
else
{
richTextBoxWeatherDetails.Clear();
richTextBoxWeatherDetails.Text = "Data Not Found!";
}
This one is a kind of web service, i wanna check the weather in some city of the countries, it should be show data not found when i choose the city that doesn't have info but it always errors. 这是一种网络服务,我想检查一些城市的天气,它应该是当我选择没有信息但总是错误的城市时找不到的数据。 It works fine when i choose the city that have the info.
当我选择有信息的城市时,它工作正常。 Can anyone help me??
谁能帮我??
You are testing weather variable like: 您正在测试天气变量,如:
if(weather != "Data not found")
C# String comparisons are case sensitive by default. 默认情况下,C#字符串比较区分大小写。 You need a case insensitive comparison.
您需要不区分大小写的比较。
Change it to 将其更改为
if(string.Compare(weather, "data not found", System.StringComparison.OrdinalIgnoreCase) != 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.