Write a program to print the volume of a box by creating a class named 'Volume' with an initialization list to initialize its length, breadth and height. (just to make you familiar with initialization lists) c#
using System;
class Volume
{
public double length { get; set; }
public double breadth { get; set; }
public double height { get; set; }
public void CalculateVolume()
{
Console.WriteLine($"Volume: {length * breadth * height}");
}
}
class Program
{
static void Main(String[] args)
{
Volume vol = new Volume()
{
length = 2,
breadth = 3,
height = 4
};
vol.CalculateVolume();
}
}
Comments
Leave a comment