   [C#] Chaining constructors.  How can I change call constructor in this case?
  If I have a constructor as follows:   public Quadrangle(Vector3 position, float width, float height, Matrix rotation, int texture)   {I can chain it using the following:   public Quadrangle()  : this(Vector3.Zero, 1.0f, 1.0f, Matrix.Identity, 0) { }How can then I call the constructor from inside another constructor should a parameter need to be calculated first?For example, here I calculate the rotation based off the input normal:   public Quadrangle(Vector3 position, float width, float height, Vector3 normal, int texture)   {  normal.Normalize();  rotation.Backward = normal;  rotation.Up = Vector3.Cross(Vector3.UnitY, normal);  if (rotation.Up.LengthSquared() < Math_Util.EPSILON)  { rotation.Up = Vector3.Cross(-Vector3.UnitZ, normal);  }  rotation.Up.Normalize();  rotation.Right = Vector3.Cross(rotation.Up, normal);  rotation.Right.Normalize();  Quadrangle(position, width, height, rotation, texture);   }However, the final line is not allowed and gives this error:'Cthonian.Quadrangle' is a 'type' but is used like a 'variable'Any suggestions?   
  not sure but maybe try:Quadrangle::Quadrangle(position, width, height, rotation, texture);This looks like a particulally weird way of doing this. What I would do is to put common constructor code into a seperate function:Quadrangle Construct(position, width, height, rotation, texture){// set all the attributes}  public Quadrangle(Vector3 position, float width, float height, Vector3 normal, int texture)   {   // all the code you had   Construct(position, width, height, rotation, texture)}and the constructor you have that does (if you have one) take a rotation should just pass all input directly to the "Construct" function.Its a fairly neat way of doing things when you might have multiple constructors as it keeps all the duplicate code in one space thus reducing possible bugs when you change things.   ;  Something like this perhaps?   public Quadrangle()   {  Create(Vector3.Zero, 1.0f, 1.0f, Matrix.Identity, 0);   }   public Quadrangle(Vector3 position, float width, float height, Vector3 normal, int texture)   {  normal.Normalize();  rotation.Backward = normal;  rotation.Up = Vector3.Cross(Vector3.UnitY, normal);  if (rotation.Up.LengthSquared() < Math_Util.EPSILON)  { rotation.Up = Vector3.Cross(-Vector3.UnitZ, normal);  }  rotation.Up.Normalize();  rotation.Right = Vector3.Cross(rotation.Up, normal);  rotation.Right.Normalize();  Create(position, width, height, rotation, texture);   }   public Quadrangle(Vector3 position, float width, float height, Matrix rotation, int texture)   {  Create(position, width, height, rotation, texture);   }   private void Create(Vector3 position, float width, float height, Matrix rotation, int texture)   {I don't see any problems with that.  I was trying to take advantage of C# specific structural ideas, but this will do just fine.   ;  For myself, generally, for anything non-trivial, all of the actual construction of data takes place in a "void Set(data)" method. Constructors just call Set() methods. Those Set() methods may call other Set() methods and constructors.   ;  Ugh.Don't move to two-phase construction for this like the others are suggesting. Two-phase construction should generally be seen as reaching deep into the bag of tricks.Instead, encapsulate the translation work into a function, and then use that function to translate the arguments.BTW, this is constructor forwarding, not chaining. (Method chaining is when you write something like foo.bar().baz(); naturally this doesn't make sense to do with constructors.)Something like this:private static Rotation rotationFrom(Vector3 normal) {  normal.Normalize();  Rotation rotation;  rotation.Backward = normal;  rotation.Up = Vector3.Cross(Vector3.UnitY, normal);  if (rotation.Up.LengthSquared() < Math_Util.EPSILON)  {    rotation.Up = Vector3.Cross(-Vector3.UnitZ, normal);  }  rotation.Up.Normalize();  rotation.Right = Vector3.Cross(rotation.Up, normal);  rotation.Right.Normalize();  return rotation;}public Quadrangle(Vector3 position, float width, float height, Vector3 normal, int texture) : this(position, width, height, rotationFrom(normal), texture) {};  I leave town for the weekend and come back to find I've somehow irritated you again Zahlman.Frustrations aside,  I learned about chaining constructors from  here, but I've probably got the wrong end of the stick from that article.Thank you for the tips, I shall put the static function with the quadrangle class.[Edited by - Spa8nky on April 26, 2010 11:53:05 AM]