c# sharp 中對ref class 作引數的試驗
阿新 • • 發佈:2019-01-31
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication1
{
interface I
{
}
class A
{
public int c;
public void f(int a,int b)
{
Console.WriteLine(a+b);
}
}
internal class B : A,I
{
}
class Program
{
static void Main(string[] args)
{
A a = new A();
A b;
a.c = 100;
b = a;
SetI(ref a,b);
Console.WriteLine(a.c+" "+b.c);
Console.Read();
}
static void SetI(ref A x ,A y)
{
A a = new A();
a.c = 200;
x = a;
// y = x; // no use..
SetII(x);
}
static void SetII(A x)
{
x.c = 300;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
namespace ConsoleApplication1
{
interface I
{
}
class A
{
public int c;
public void f(int a,int b)
{
Console.WriteLine(a+b);
}
}
internal class B : A,I
{
}
class Program
{
static void Main(string[] args)
{
A a = new A();
A b;
a.c = 100;
b = a;
SetI(ref a,b);
Console.WriteLine(a.c+" "+b.c);
Console.Read();
}
static void SetI(ref A x ,A y)
{
A a = new A();
a.c = 200;
x = a;
// y = x; // no use..
SetII(x);
}
static void SetII(A x)
{
x.c = 300;
}
}
}