如何调整"是一种类型,但使用像变量"? [英] how to adjust "is a type but is used like a variable"?
本文介绍了如何调整"是一种类型,但使用像变量"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想产生一些code在Web服务。但是,它的返回2个错误:
I'm trying to generate some code in a web service. But it's returning 2 errors:
1)名单是一个类型,但使用像变量
1) List is a type but is used like a variable
2)无过载方法客户需要3个参数
2) No overload for method 'Customer' takes '3 arguments'
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class wstest : System.Web.Services.WebService
{
[WebMethod]
public List<Customer> GetList()
{
List<Customer> li = List<Customer>();
li.Add(new Customer("yusuf", "karatoprak", "123456"));
return li;
}
}
public class Customer
{
private string name;
private string surname;
private string number;
public string Name { get { return name; } set { name = value; } }
public string SurName { get { return surname; } set { surname = value; } }
public string Number { get { return number; } set { number = value; } }
}
如何调整上述错误?
How can i adjust above error?
推荐答案
现在的问题是在该行
List<Customer> li = List<Customer>();
您需要添加新
List<Customer> li = new List<Customer>();
此外下一行应该是:
li.Add(new Customer{Name="yusuf", SurName="karatoprak", Number="123456"});
编辑:如果您使用的是VS2005,那么你必须创建一个新的构造函数的3个参数
If you are using VS2005, then you have to create a new constructor that takes the 3 parameters.
public Customer(string name, string surname, string number)
{
this.name = name;
this.surname = surname;
this.number = number;
}
这篇关于如何调整&QUOT;是一种类型,但使用像变量&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文