From the course: Learning C#

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Reference and out parameters

Reference and out parameters - C# Tutorial

From the course: Learning C#

Reference and out parameters

- [Narrator] The C# language has some interesting, unique features, and we're going to look at a couple of them in this example. So let's open up our RefAndOutParams folder, and we'll open up the program code. So ordinarily, when you pass value arguments to a function, that function can't change the values of those arguments outside the function. So let's see an example of this. Here I have a function that takes a single integer argument. And inside the function, if I add some code, and I'm going to modify the argument, so let's do something like arg1 plus equals 10. So we're going to increment arg1 by 10. This change is only temporary inside this function because the function receives a copy of the value in the argument when it is passed in. So down here in the main function, when I call this function in main, and I print out the result, the value doesn't change. And we'll see that that's the case when I run the code. So…

Contents