在此代码中(来自 WCF REST starterkit - preview2):
protected override SampleItem OnAddItem(SampleItem initialValue, out string id)
{
// TODO: Change the sample implementation here
id = Guid.NewGuid().ToString();
this.items.Add(id, initialValue);
return initialValue;
}
我是返回字符串形式的 id,还是返回 SampleItem 形式的 initialValue?
编辑: 看起来我都回来了,那么将方法调用的简单示例分配给几个变量会是什么样子呢?
最佳答案
您将在作为参数传递给该方法的字符串中取回 id。此外,该方法将返回 SampleItem 实例。
SampleItem myItem = new SampleItem();
string newId = string.Empty;
myItem = OnAddItem(myItem, out newId);
// now myItem will be assigned with SampleItem returned from the
// OnAddItem method, and newId will be updated with the id assigned
// within that method
关于c# - 关于返回的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/883168/