代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int b = 1;
test(b);
Console.WriteLine(b);
my m = new my();
test2(m);
Console.WriteLine(m.Value);
test3(m);
Console.WriteLine(m.Value);
test4(ref m);
Console.WriteLine(m.Value);
Console.ReadLine();
}
private static void test(int a)
{
a = 2;
}
private static void test2(my a)
{
a.Value = 200;
}
private static void test3(my a)
{
a = new my();
a.Value = 300;
}
private static void test4(ref my a)
{
a = new my();
a.Value = 400;
}
}
class my
{
public int Value = 100;
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int b = 1;
test(b);
Console.WriteLine(b);
my m = new my();
test2(m);
Console.WriteLine(m.Value);
test3(m);
Console.WriteLine(m.Value);
test4(ref m);
Console.WriteLine(m.Value);
Console.ReadLine();
}
private static void test(int a)
{
a = 2;
}
private static void test2(my a)
{
a.Value = 200;
}
private static void test3(my a)
{
a = new my();
a.Value = 300;
}
private static void test4(ref my a)
{
a = new my();
a.Value = 400;
}
}
class my
{
public int Value = 100;
}
}
代码
package
{
import flash.display.Sprite;
public class Test extends Sprite
{
private var refValue:Array;
private var value:int;
public function Test()
{
testArg(value,refValue);
trace(value,refValue);
refValue = [0];
value = 0;
testArg(value,refValue);
trace(value,refValue);
testArg2(value,refValue);
trace(value,refValue);
}
private function testArg(value:int,refValue:Array):void{
trace(this.value==value,this.refValue==refValue);
value = 1;
refValue = [1];
trace(this.value==value,this.refValue==refValue);
}
private function testArg2(value:int,refValue:Array):void{
trace(this.value==value,this.refValue==refValue);
value += 1;
refValue.push(1);
trace(this.value==value,this.refValue==refValue);
}
}
}
{
import flash.display.Sprite;
public class Test extends Sprite
{
private var refValue:Array;
private var value:int;
public function Test()
{
testArg(value,refValue);
trace(value,refValue);
refValue = [0];
value = 0;
testArg(value,refValue);
trace(value,refValue);
testArg2(value,refValue);
trace(value,refValue);
}
private function testArg(value:int,refValue:Array):void{
trace(this.value==value,this.refValue==refValue);
value = 1;
refValue = [1];
trace(this.value==value,this.refValue==refValue);
}
private function testArg2(value:int,refValue:Array):void{
trace(this.value==value,this.refValue==refValue);
value += 1;
refValue.push(1);
trace(this.value==value,this.refValue==refValue);
}
}
}