方法必须有返回类型? [英] Method must have a return type?

查看:166
本文介绍了方法必须有返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class xmlC : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   {
      if (!this.IsPostBack) {
         //Create a new global weather object
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         //Create a new xml document object. We need xml implementation since the data is in xml format.
         XmlDocument xmlDoc = new XmlDocument();
         //Load all country/city names in to the xml document.
         xmlDoc.LoadXml(proxy.GetCitiesByCountry(""));
         //Query only country names and put them in to xml node list
         XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("Country");
         List<string> countryList = new List<string>();
         foreach (XmlNode node in xmlNodes) {
            if (!countryList.Contains(node.InnerText)) {
               //Loop through the country names and put them in to a list object
               countryList.Add(node.InnerText);
            }
         }
         countryList.Sort();
         //Bind the CountryDropDownList control.
         this.CountryDropDownList.DataSource = countryList;
         this.CountryDropDownList.DataBind();
         this.CountryDropDownList_SelectedIndexChanged(this.CountryDropDownList, new EventArgs());
      }
   }

   protected void CountryDropDownList_SelectedIndexChanged(object sender, System.EventArgs e)
   {
      if (this.CountryDropDownList.SelectedItem != null) {
         List<string> cityList = new List<string>();
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         XmlDocument xmlDoc = new XmlDocument();
         //Load the xml document with all city names for the selected country.
         xmlDoc.LoadXml(proxy.GetCitiesByCountry(this.CountryDropDownList.SelectedValue));
         //Get all city names and put them in to xml node list.
         XmlNodeList xmlNodes = xmlDoc.GetElementsByTagName("City");
         foreach (XmlNode node in xmlNodes) {
            if (!cityList.Contains(node.InnerText)) {
               //Loop through the city names and put them in to a list object
               cityList.Add(node.InnerText);
            }
         }
         cityList.Sort();
         //Bind the CityDropDownList control.
         this.CityDropDownList.DataSource = cityList;
         this.CityDropDownList.DataBind();
      }
      else {
         this.CityDropDownList.DataSource = null;
         this.CityDropDownList.DataBind();
      }
   }

   protected void Page_LoadComplete(object sender, System.EventArgs e)
   {
      if (this.CountryDropDownList.SelectedItem != null && this.CityDropDownList.SelectedItem != null) {
         StringBuilder sb = new StringBuilder();
         GlobalWeather.GlobalWeather proxy = new GlobalWeather.GlobalWeather();
         //Get weather information for the selected country and city by using the "GetWeather" service method.
         string xmlStr = proxy.GetWeather(this.CityDropDownList.SelectedValue, this.CountryDropDownList.SelectedValue);
         bool success = false;
         try {
            XmlDocument xmlDoc = new XmlDocument();
            //Load the xml string data into xml document
            xmlDoc.LoadXml(xmlStr);
            XmlNode xmlNode = xmlDoc.DocumentElement();
            foreach (XmlNode node in xmlNode.ChildNodes) {
               if (node.Name == "Status") {
                  success = node.InnerText == "Success";
               }
               else {
                  //Loop through the nodes and put the information in the StringBuilder object.
                  sb.Append("" + node.Name + ": " + node.InnerText + "<br />");
               }
            }
         }
         catch (Exception ex) {
            sb.Append("Data Not Found");
         }
         if (success) {
            //If everything went well than show the information.
            this.weatherLabel.Text = sb.ToString;
         }
         else {
            this.weatherLabel.Text = "Data Not Found";
         }
      }
   }
   public _Default()
   {
      LoadComplete += Page_LoadComplete;
      Load += Page_Load;
      retu;
   }
}

推荐答案

问题是你已经声明了一个方法(public _Default())而没有返回类型



在下面的代码中什么是retu; ?

public _Default()

{

LoadComplete + = Page_LoadComplete;

Load + = Page_Load;

retu;

}



如果您不想退货,请将其更改为



The problem is you have declared a method (public _Default()) without a return type

In the below code what is retu; ?
public _Default()
{
LoadComplete += Page_LoadComplete;
Load += Page_Load;
retu;
}

If you don't want to return anything then change it to

public void _Default()
     {
         LoadComplete += Page_LoadComplete;
         Load += Page_Load;

     }


是的,方法必须具有返回类型。 C#编程语言需要这样。不返回值的方法必须声明 void
Yes, methods must have the return type. The C# programming language requires that. Methods that return no value must be declared void.


这是什么意思?

what does this mean?
public _Default()
{
LoadComplete += Page_LoadComplete;
Load += Page_Load;
retu;
}





更改此代码块,因为这会导致错误。



change this block of code as this is causing error.


这篇关于方法必须有返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆