本文介绍了browsebutton_Click(object,System.Net.DownloadStringCompletedEventArgs,dynamic,int)':并非所有代码路径都返回一个值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 您好,我在这里执行了按钮点击事件的代码,我从中传递了值browseurl和browseitem。我想在调用函数wc_DownloadStringCompletedbrowse时传递这些值,但它显示错误。点击按钮是: browsebutton.Click + = new EventHandler ((sender1,e1)= > browsebutton_Click(sender,e,browseurl,browsingitem)); 在其点击事件中,我执行了此代码,但在行中的'browsebutton_Click'上显示错误(私有对象browsebutton_Click(对象发件人,DownloadStringCompletedEventArgs e,动态浏览,int browseitem)) 和错误是: private object browsebutton_Click( object sender,DownloadStringCompletedEventArgs e ,动态 browseurl, int browseitem) { WebClient wc = new WebClient(); wc.DownloadStringAsync( new Uri( http://dev.livestuff.com/ + browseurl)); wc.DownloadStringCompleted + = wc_DownloadStringCompletedbrowse(sender,e,browseurl,browsingitem); } void wc_DownloadStringCompletedbrowse( object sender,DownloadStringCompletedEventArgs e, 动态 browseurl, int browseitem) { var serializer = new JavaScriptSerializer(); serializer.RegisterConverters( new [] { new DynamicJsonConverter()}); dynamic obj = serializer.Deserialize(e.Result, typeof (对象)); } 请给我任何代码,通过该代码我可以传递browseurl和browseitem的价值。 谢谢。解决方案 browsebutton_Click()被定义为返回对象。在方法的代码中,没有返回语句。 返回一些东西,或者,如果没有要返回的话,将方法的返回值更改为 void 。 您收到错误,因为您没有使用 return 声明。如果您不需要返回某些内容,请在您的方法中将 object 更改为 void : 私有 无效 browsebutton_Click( object sender,DownloadStringCompletedEventArgs e, dynamic browseurl, int browseitem) 如果您需要返回某些内容,请在方法结尾处使用 return 语句: 返回 theObjectThatYouWantToReturn ; 你在评论中说你还有问题。以下是如何修复它: wc.DownloadStringCompleted + = new DownloadStringCompletedEventHandler((sndr,ev) = > wc_DownloadStringCompletedbrowse(sndr,ev,browseurl,browsingitem)); Quote:私有对象browsebutton_Click(对象发送者,DownloadStringCompletedEventArgs e,动态浏览, int browitem) { WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri(http:// dev。 livestuff.com/+ browseurl)); wc.DownloadStringCompleted + = wc_DownloadStringCompletedbrowse(sender,e,browseurl,browsingitem); } 您的浏览按钮单击方法定义具有返回类型作为对象但您没有返回任何对象,因此它给出了错误。 尝试如下 private object browsebutton_Click( object sender,DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem) { WebClient wc = new WebClient(); wc.DownloadStringAsync( new Uri( http://dev.livestuff.com/ + browseurl)); return wc.DownloadStringCompleted + = wc_DownloadStringCompletedbrowse(sender,e,browseurl,browsingitem); } 谢谢, -RG Hello, Here I did the code for button click event from where I pass the value browseurl and browsingitem. I want to pass these values when I call the function wc_DownloadStringCompletedbrowse, but it showing error. The click button is :browsebutton.Click += new EventHandler((sender1, e1) => browsebutton_Click(sender, e, browseurl, browsingitem));On its click event I did this code, but is showing error on 'browsebutton_Click' in line(private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem))and error is:private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem){ WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl)); wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);}void wc_DownloadStringCompletedbrowse(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem){ var serializer = new JavaScriptSerializer(); serializer.RegisterConverters(new[] { new DynamicJsonConverter() }); dynamic obj = serializer.Deserialize(e.Result, typeof(object));}Please give me any code through which I can pass the value of browseurl and browsingitem.Thanks. 解决方案 browsebutton_Click() is defined to return something of type object. In the method's code, there is no return statement.Return something or, if nothing is to be returned, change the method's return value to void.You get the error because you don't return any value using a return statement. If you don't need to return something, change object into void in your method:private void browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem)If you need to return something, use a return statement at the end of your method:return theObjectThatYouWantToReturn;[Edit]You said in your comment that you have still a problem. Here is how to fix it:wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((sndr, ev) => wc_DownloadStringCompletedbrowse(sndr, ev, browseurl, browsingitem));Hi,Quote:private object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem){ WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl)); wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);}Your browsebutton click method definition has return type as object but you haven't return any object so it is giving error.try as belowprivate object browsebutton_Click(object sender, DownloadStringCompletedEventArgs e, dynamic browseurl, int browsingitem){ WebClient wc = new WebClient(); wc.DownloadStringAsync(new Uri("http://dev.livestuff.com/" + browseurl)); return wc.DownloadStringCompleted += wc_DownloadStringCompletedbrowse(sender, e, browseurl,browsingitem);}Thanks,-RG 这篇关于browsebutton_Click(object,System.Net.DownloadStringCompletedEventArgs,dynamic,int)':并非所有代码路径都返回一个值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-24 23:06