來試試Class版本
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var test1 = new ClassTest();
var test2 = new ClassTest();
test1.value = 100;
test2.value = 200;
Console.WriteLine("Test1 value = {0} Test2 value = {1}", test1.value, test2.value);
TestRefObject(test1, ref test2);
Console.WriteLine("After TestRefObject function Test1 value = {0} Test2 value = {1}", test1.value, test2.value);
Console.ReadLine();
}
private static void TestRefObject(ClassTest test1, ref ClassTest test2 )
{
test1.value = 101;
test2.value = 202;
test1 = new ClassTest();
test1.value = 1001;
test2 = new ClassTest();
test2.value = 2002;
}
class ClassTest
{
public ClassTest() { }
public int value = 0;
}
}
}
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var test1 = new ClassTest();
var test2 = new ClassTest();
test1.value = 100;
test2.value = 200;
Console.WriteLine("Test1 value = {0} Test2 value = {1}", test1.value, test2.value);
TestRefObject(test1, ref test2);
Console.WriteLine("After TestRefObject function Test1 value = {0} Test2 value = {1}", test1.value, test2.value);
Console.ReadLine();
}
private static void TestRefObject(ClassTest test1, ref ClassTest test2 )
{
test1.value = 101;
test2.value = 202;
test1 = new ClassTest();
test1.value = 1001;
test2 = new ClassTest();
test2.value = 2002;
}
class ClassTest
{
public ClassTest() { }
public int value = 0;
}
}
}
結論就是型別是Class 也一樣會有效果
沒有留言:
張貼留言