Using Static Property C# with Example



Using Static Property C# with Example

 	using System;

	namespace CSharpClass{
		class Box{
			public static double count{get; set;}
			double width{get; set;}
			double height{get; set;}
			double length{get; set;}
			
			public void SetSize(double h, double l, double w){
				height = h;
				width = w;
				length = l;
				count++;
			}
		}
		
		class UsingBoxClassWithStaticProperty {
			static void Main(String[] arg){
				Console.WriteLine("CPU Cabinet Information");
				Box cpuCabinet = new Box();
				cpuCabinet.SetSize(10, 20, 30);
				Console.WriteLine("Total Object Created: "+ Box.count);
				
				Console.WriteLine("\nHard Disk Information");
				Box hardDisk = new Box();
				hardDisk.SetSize(5, 8, 10);
				Console.WriteLine("Total Object Created: "+ Box.count);
				
				Console.WriteLine("\nMonitor Information");
				Box monitor = new Box();
				monitor.SetSize(10, 3, 20);
				Console.WriteLine("Total Object Created: "+ Box.count);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment