As I understand it, C# passes parameters into methods by reference. In VB.NET, you can specify this with ByVal and ByRef. The default is ByVal.
Is this for compatibility with Visual Basic 6.0, or is it just random? Also, how can I specify what to use in C#? I kind of like the idea of passing parameters by value.
ByRef
in the absence of theByVal
keyword. In .net languages, the default is by value. To facilitate migration and avoid confusion, vb.net requires that parameters be explicitly marked eitherByRef
orByVal
, but the VS editor will "auto-correct" parameters without such marking by adding "ByVal". Because there was never any C#-ish language which had pass-by-ref as the default behavior, there is no problem simply saying that unmarked parameters are pass-by-value.ByVal
when that's what I meant 99% of the time. Always thought it was kind of silly - knowing the why makes it feel slightly less silly ;)final
; my preference would be to require that closed-over variables either be markedreadonly
[equivalent tofinal
] or else explicitly declared as being capturable-by-reference, but I didn't design the languages.