.NETGURU
pass by reference in JScript.NET
Messages   Related Types
This message was discovered on microsoft.public.dotnet.languages.jscript.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

cool pal via .Net Guru (VIP)
Hi folks,

I am trying to use "pass by reference" of variables such as byte array, integers etc in JScript.NET.

Is this possible in JScript.NET?

If not, please help me out by any other approach by which we can pass the variables by reference.

Thanks a lot folks.
-Chandru

--------------------------------
From: cool pal

-----------------------
Posted by a user from .Net Guru (http://www.dot-net-guru.com/)

<Id>k992MJxrYkO5WJLxbFTN8Q==</Id>
Reply to this message...
 
    
bruce barker
in .net all objects are passed by reference, only value types are by value.
pass by ref in .net means the variable pointer is passed, so the called
method can change what object the variable is pointing to. javascript.net
does not support this.

-- bruce (sqlwork.com)

"cool pal via .Net Guru" <Click here to reveal e-mail address> wrote in message
news:%23xGbt$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Martin Honnen
cool pal via .Net Guru wrote:

[Original message clipped]

If you use .NET arrays then these are passed by reference as they are
members of a reference type, e.g. the following

import System;

public class Test2004080501 {
public static function ArrayTest (array: byte[]) : void {
Console.WriteLine("ArrayTest received array: {0}.", array);
array[0] = 32;
}

public static function Main () : void {
var array : byte[] = new byte[3];
array[0] = 2;
array[1] = 4;
array[2] = 8;
Console.WriteLine("array[0]: {0}.", array[0]);
ArrayTest(array);
Console.WriteLine("array[0]: {0}.", array[0]);
}
}

Test2004080501.Main();

outputs

array[0]: 2.
ArrayTest received array: System.Byte[].
array[0]: 32.

--

    Martin Honnen
    http://JavaScript.FAQTs.com/

Reply to this message...
 
    
Richard A. Lowe
If you mean pass by reference in the same way the the "ref" or "out"
keywords in C# or ByRef keyword in VB.NET do, then I don't think you can.

It appears all parameters are passed by value - the actual value in the case
of struct or primative value types and the value of the reference to an
object for heap-based class types. I don't think, for example, creating a
"Swap" function in JScript.NET would be possible, directly, where a function
swaps the value of two variables passed in.

An alternative is to create objects that act as parameter passers - i.e.
create a class with fields (or just an object array) and then get the values
out of that when the called function is finished.

Richard

"cool pal via .Net Guru" <Click here to reveal e-mail address> wrote in message
news:%23xGbt$Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
 
System.Byte
System.Console




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification