- Improving your C# Skills
- Ovais Mehboob Ahmed Khan John Callaway Clayton Hunt Rod Stephens
- 95字
- 2021-07-02 13:08:35
Reference returns
Reference returns allow a method to return an object as a reference instead of its value. We can define the reference return value by adding a ref keyword before the type in the method signature and when returning the object from the method itself.
Here is the signature of the method that allows reference returns:
public ref Person GetPersonInformation(int ID); Following is the implementation of the GetPersonInformation method that uses the ref keyword while returning the person's object. Person _person; public ref Person GetPersonInformation(int ID) { _person = CallPersonHttpService(); return ref _person; }