RE: Passing arrays ByVal vs ByRef

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You are correct - you would need to make a copy.
VB & C# (or Java) have no concept of marking a parameter as 'unmodifiable
internals'. You can always modify the 'internals' of the object being passed
- with reference objects, the only thing you can prevent is whether the
top-level reference is modified.
--
David Anton
http://www.tangiblesoftwaresolutions.com
Convert VB to C#, C++, or Java
Convert C# to VB, C++, or Java
Convert C++ to C#, VB, or Java
Convert Java to C#, C++, or VB


"Schizoid Man" wrote:

Hello,

I have run into a bit of a problem when passing arrays ByVal between
functions - it seems that any modifications to the passed array in the
called method will be reflected in the calling method.

A quick Web search shows that this is, in fact, the expected VB.Net
behavior. What is the way around this - is the correct procedure to make a
copy of the array in the called method and modify that?

Thanks,
Schiz


.



Relevant Pages

  • Re: which 4gl compiler
    ... I would recommend you investigate Java or PHP. ... you'll have downloadable presentations on Java. ... Hmm, actually what I was hoping was to modify what we have, as the ...
    (comp.databases.informix)
  • Re: mutate an object or create a new one?
    ... And one's computation doesn't access or modify to ... Only thing I like immutable object, ... and miss very much in Java) I try to have immutable object as ... Resetting an object is not free, neither memory allocation. ...
    (comp.lang.java.programmer)
  • Re: no pointer in Java => my problem
    ... > Chris that java can not modify the value actually passed to it. ... it can never be a parameter in Java. ... single const modifier (which is very helpful and covers most common ... Chris Smith - Lead Software Developer/Technical Trainer ...
    (comp.lang.java.programmer)
  • Re: Java books
    ... I don't think I have ever run across a book on Java Internals. ... are books on the JVM see http://mindprod.com/jgloss/jvm.html ... Memory management in Java is duck simple from the programmer's point ...
    (comp.lang.java.programmer)
  • Re: no pointer in Java => my problem
    ... Timo Wrote ... it can't modify the value of any ... > of the value should be a clear indication. ... > caller's stackframe in Java. ...
    (comp.lang.java.programmer)