2009-05-19 50 views
1

在此代码(从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?

编辑: 貌似我得到两个回来,所以会是什么方法调用看一个简单的例子像分配给一对夫妇的变量?

回答

4

您将返回作为参数传递给方法的字符串中的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 
+0

谢谢,这是有道理的。 – madcolor 2009-05-19 14:45:00

1

你们都回来了。

您将传递一个字符串变量作为ID,并将通过'out'修饰符返回给您。该函数还会返回您传入的SampleItem实例initialValue。

0

您正在取回两者。参数out只是返回某些编程语言提供的值的另一种方式。