[英]Question about Out and Return?
在此代碼中(從WCF REST入門工具包-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
你們都得到了。
你們都回來了。
您將傳入ID的字符串變量,該變量將通過'out'修飾符返回給您。 該函數還將返回您傳入的SampleItem實例initialValue。
你們都回來了。 out
參數只是返回某些編程語言提供的值的另一種方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.