0

Possible Duplicate:
Are arrays or lists passed by default by reference in c#?

I have read some contradicting posts on here about C# and whether arrays are passed by value or by reference. Could someone clarify whether C# arrays are passed by value or by reference?

Thanks

Community
  • 1
  • 1
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216

2 Answers2

10

The reference to the array is passed by value. This is the source of the confusion :-)

Krzysztof Kozielczyk
  • 5,887
  • 37
  • 28
1

When you change elements inside array, inside a function it will affect array outside of that function but it not means that it is passed by reference by default :).

You can see this for more clarification http://msdn.microsoft.com/en-us/library/szasx730(v=vs.71).aspx

Grzegorz Gajos
  • 2,253
  • 19
  • 26