Search:
Namespaces
Discussions
.NET v1.1
Feedback
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 247 (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 247 (
http://www.dotnet247.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 247" <
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 247 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 247" <
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com