- C# 7 and .NET Core 2.0 High Performance
- Ovais Mehboob Ahmed Khan
- 95字
- 2021-08-27 18:47:10
Reference returns
Reference returns allows 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; }