Parameterized constructors. - CSharp Custom Type

CSharp examples for Custom Type:Constructor

Description

Parameterized constructors.

Demo Code

using System;/*from w  w w .  j a  v  a 2  s  . c om*/
class Line {
   private double length;   // Length of a line
   public Line(double len) {  //Parameterized constructor
   Console.WriteLine("Object is being created, length = {0}", len);
   length = len;
}
public void setLength( double len ) {
   length = len;
}
public double getLength() {
   return length;
}
static void Main(string[] args) {
   Line line = new Line(10.0);
   Console.WriteLine("Length of line : {0}", line.getLength());
   line.setLength(6.0);
   Console.WriteLine("Length of line : {0}", line.getLength());
}
}

Result


Related Tutorials