What do you call those statements highlighted in red?

``````using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main()
{
int choice;

Console.WriteLine();
Console.WriteLine("1. Area of a Circle");
Console.WriteLine("2. Area of a Rectangle");
Console.WriteLine("3. Area of a Cylinder");
Console.WriteLine();

if (choice == 1)
{
Console.Clear();
aCircle();

}
if (choice == 2)
{
Console.Clear();
aRectangle();
}
if (choice == 3)
{
Console.Clear();
aCylinder();
}
Console.Write("Do you wish to try again? : ");

}

static void aCircle()
{
int r;
double A;
A = 3.14 * r * r;
Console.WriteLine("The Area of circle of given radius is="+A);
}
static void aRectangle()
{
int w, h;
int ar;
Console.WriteLine("Enter the width:");
Console.WriteLine("Enter the height:");
ar = w * h;
Console.WriteLine("The Area of rectangle is=" + ar);

}
static void aCylinder()
{
double rc;
double hc;
double ac;
double pi=3.14;
Console.WriteLine("Enter the height:");
ac = 2 * pi * rc*rc + 2 * pi * rc * hc;
Console.WriteLine("The Area of cylinder is=" + ac);
}

}
}``````

Another question.

This is an example of a constructor method:

``````public double multiply(double nFirst, double nSecond)
{
}``````

now what makes it a constructor method and how is it different from a normal method?

Edited by king03: n/a

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Momerath

First Question: Those are static methods. Also known as class methods.

Second Question: That's not a constructor. Constructors don't have a explicit return type, while this one does (double).

Edited by Momerath: n/a

First Question: Those are static methods. Also known as class methods.

Second Question: That's not a constructor. Constructors don't have a explicit return type, while this one does (double).

oh yeah thanks, if that wasn't a constructor then what do you call it?

Also this is what I meant by constructor:

``public mySampleClass()``

Edited by king03: n/a

oh yeah thanks, if that wasn't a constructor then what do you call it?

It's a method.

Also this is what I meant by constructor:

``public mySampleClass()``

A constructor has the same name as the class it is in and has no explicit return type. For example

``````MyClass {
public int Value { get; set; } // Automatic property

public MyClass() { // Parameterless constructor

public MyClass(int v) {  // Constructor that takes an int
Value = v;
}

public MyClass(String s) { // Constructor that takes a string
int v;
if (Int32.TryParse(s, out v) == false) {
throw new ArgumentException("Parameter must be an integer");
}
Value = v;
}
}``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.