Can I use a parameter in C # to send data back to the caller?

Usually I send data back to the calling code using return. However, this time I need to send two kinds of data:

public IEnumerable<AccountDetail> ShowDetails(string runTime) 

Is it possible to send the runTime value back to the calling code?

+7
source share
3 answers

Yes

 public IEnumerable<AccountDetail> ShowDetails(ref string runTime) 

The calling code will also have the ref keyword:

 .ShowDetails(ref runTime); 
+7
source

Yes, this is possible with ref or out .

Usually, however, the need for this indicates a design failure elsewhere ... not always, there are a few good cases for this, but often enough that I want to spend a little time thinking about what I "I really do first" .

+9
source

There are three options.

  • ref keyword
  • out variable
  • Global variable
+3
source

All Articles