P
Paul Selormey
Consider the following codes:
----------------------------------------------------
using System;
namespace ConsoleApplication1
{
interface IPointD
{
double X {get; set;}
double Y {get; set;}
}
struct PointD : IPointD
{
private double x;
private double y;
public PointD(double x, double y)
{ this.x = x; this.y = y;}
public double X
{
get { return x; }
set { x= value; }
}
public double Y
{
get { return y; }
set { y = value; }
}
}
class Class1
{
static void Method(IPointD point)
{
if (point != null)
{
point.X = 10;
point.Y = 10;
}
}
[STAThread]
static void Main(string[] args)
{
PointD point = new PointD(1, 1);
IPointD dPoint = (IPointD)point;
Method(dPoint);
Console.WriteLine("X = {0}, Y = {1}", point.X, point.Y);
}
}
}
---------------------------------------------------------
Why is the call to the method - Method(dPoint) not by reference?
Best regards,
Paul.
----------------------------------------------------
using System;
namespace ConsoleApplication1
{
interface IPointD
{
double X {get; set;}
double Y {get; set;}
}
struct PointD : IPointD
{
private double x;
private double y;
public PointD(double x, double y)
{ this.x = x; this.y = y;}
public double X
{
get { return x; }
set { x= value; }
}
public double Y
{
get { return y; }
set { y = value; }
}
}
class Class1
{
static void Method(IPointD point)
{
if (point != null)
{
point.X = 10;
point.Y = 10;
}
}
[STAThread]
static void Main(string[] args)
{
PointD point = new PointD(1, 1);
IPointD dPoint = (IPointD)point;
Method(dPoint);
Console.WriteLine("X = {0}, Y = {1}", point.X, point.Y);
}
}
}
---------------------------------------------------------
Why is the call to the method - Method(dPoint) not by reference?
Best regards,
Paul.