Box Class Multiple Instance C# with Example



Box Class Multiple Instance C# with Example

 	using System;

	namespace CSharpClass{
		class Box{
			double width;
			double height;
			double length;

			private double Volume(){
				double volume;
				volume = length * height * width;
				return volume;
			}
			
			public void SetSize(double h, double l, double w){
				height = h;
				width = w;
				length = l;
			}
			
			public void Display(){
				Console.WriteLine("Height: " + height);
				Console.WriteLine("Width: " + width);
				Console.WriteLine("Length: " + length);
				Console.WriteLine("Volume: " + Volume());
			}
		}
		
		class UsingBoxClass {
			static void Main(String[] arg){
				Console.WriteLine("CPU Cabinet Information");
				Box cpuCabinet = new Box();
				cpuCabinet.SetSize(10, 20, 30);
				cpuCabinet.Display();
				
				Console.WriteLine("\nHard Disk Information");
				Box hardDisk = new Box();
				hardDisk.SetSize(5, 8, 10);
				hardDisk.Display();
				
				Console.WriteLine("\nMonitor Information");
				Box monitor = new Box();
				monitor.SetSize(10, 3, 20);
				monitor.Display();
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment