Guest User

Guest User

  • Tech Writer
  • 357
  • 120.6k

Why does the return statement have to be t.x; ?

Aug 21 2012 12:06 PM
Hi

Given the following code I came across:-


class MyImmutableType
{
 public readonly double x;
 public MyImmutableType(double _x) { x = _x; }
 public MyImmutableType Square() { return new MyImmutableType(x*x); }
}

static
 double SomeMethod(MyImmutableType t)
{
 t = t.Square();
 return t.x;
}

Why does the return statement have to be t.x;
rather than just t, as t holds the return value of Square?

I appreciate that the return type of SomeMethod is double and x is of type double so it could be due to a type conversion\cast error.

Regards
Steven

Answers (3)