Question about leaving and returning?

In this code (from 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 returning id as String or initialValue as SampleItem?

Edit: It looks like I'm going back so that a simple example of a method call looks like being assigned to multiple variables?

+1


a source to share


4 answers


You will return the identifier on the string that you pass as a parameter to the method. Additionally, the method will return a 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

      

+4


a source


You get both.



+1


a source


You get both back.

You will pass a string variable for the identifier and it will be returned to you with the 'out' modifier. The function will also return the original SampleItem instance number that you passed.

+1


a source


You return both. A parameter out

is another way to return a value suggested by some programming languages.

0


a source







All Articles