简体   繁体   English

InvalidOperationException未处理c#

[英]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.

相关问题 C#WPF InvalidOperationException未处理 - c# WPF InvalidOperationException was unhandled 未处理InvalidOperationException不允许更改&#39;ConnectionString&#39;属性。 在C#上 - InvalidOperationException was unhandled Not allowed to change the 'ConnectionString' property. On C# 未处理System.InvalidOperationException-XMl序列化C# - System.InvalidOperationException was unhandled - XMl Serialization C# 发生未处理的异常C#的system.data.dll中发生了类型&#39;system.invalidoperationexception&#39;的未处理异常 - An unhandled exception occured an unhandled exception of type 'system.invalidoperationexception' occurred in system.data.dll in c# List.Sort()引发mscorlib.dll中发生类型为&#39;System.InvalidOperationException&#39;的未处理异常-C# - List.Sort() throws An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll - C# C# 中的 System.Data.dll 中发生了“System.InvalidOperationException”类型的未处理异常 - An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll in C# System.Data.dll中发生类型为&#39;System.InvalidOperationException&#39;的未处理异常-C#Visual Studio - An unhandled exception of type 'System.InvalidOperationException' occurred in System.Data.dll - C# visual studio 未处理InvalidOperationException - InvalidOperationException was unhandled C# Linq InvalidOperationException - C# Linq InvalidOperationException ConcurrentDictionary InvalidOperationException c# - ConcurrentDictionary InvalidOperationException c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM