Right Triangle Read Only Computed Property C# with Example



Right Triangle Read Only Computed Property C# with Example

 	using System;

	namespace CSharpClass{
		class RightTriangle
		{
			public double L;
			public double A;

			public double Hypotenuse // Read-only property
			{
				get{ return Math.Sqrt((A*A)+(L*L)); } // Calculate return value
			}
		}

		class Program
		{
			static void Main()
			{
				RightTriangle objTR = new RightTriangle();
				objTR.L = 3;
				objTR.A = 4;
				Console.WriteLine("Hypotenuse: {0}", objTR.Hypotenuse);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment