tags:

views:

62

answers:

4

In this code (from the 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;
        }

Am I getting back id as String, or the initialValue as SampleItem?

Edit: Looks like I get both back, so what would a simple example of the method call look like assigned to a couple of variables?

+1  A: 

You're getting both.

Randolpho
+4  A: 

You will get back id in the string that you pass as a parameter to the method. Also, the method will return the SampleItem instance.

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
Fredrik Mörk
thanks, that makes sense.
madcolor
+1  A: 

You are getting back both.

You will pass in a string variable for ID and that will be returned to you via the 'out' modifier. The function will also return the SampleItem instance initialValue that you passed in.

Lazarus
A: 

You are getting back both. An out parameter is just an additional way to to return a value offered by some programming languages.

n3rd