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
  • 14,265
  • 50
  • 130
  • 208

2 Answers2

10

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

Krzysztof Kozielczyk
  • 5,788
  • 35
  • 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,143
  • 17
  • 26