【发布时间】:2015-04-09 12:53:28
【问题描述】:
谁能向我解释我将如何将这个场景作为一种 Web 服务方法(我给自己做这个练习是为了学习)。
物品清单及其价格; book0.50,notepad1.20。然后是用户输入金额的一种方式,因此如果他们在文本框中输入 1,如果他们输入 2 并选择记事本,则金额为 2.40。
我需要两个 Web 方法吗?存放东西的最佳方式是什么?我已经尝试过了,但我得到了我没有重载方法的错误:
[WebMethod]
public ThingsPrices[] GetThings(string thing, decimal price)
{
List<ThingsPrices> things = new List<ThingsPrices>();
things.Add(new ("book", 0.50);
things.Add("notepad", 1.20); //No overload for method Add??
return things.ToArray();
}
【问题讨论】:
-
你能提供
ThingsPrices的代码吗? -
我们可以看看你对
ThingsPrices的定义吗?您确实有语法问题,但如果没有定义,我们无法可靠地向您展示应该更正的内容。 -
您收到有关构造函数的错误的原因是您尝试将 List.Add() 与字符串和数字一起使用。该方法只接受一个对象。你可能想要做的是这样的:
things.Add(new ThingsPrices("notepad", 1.20));
标签: c# asp.net arrays web-services