Using Computation In Accessors C# with Example



Using Computation In Accessors C# with Example

 	using System;

	namespace CSharpClass{
		class PropertyClass
		{
			private int TheRealValue;
			public int MyValue
			{
				set
				{ 
					if(value > 100)
						TheRealValue = value;
					else
						TheRealValue = 300;
				}
				get{ return TheRealValue; }
			}
		}
		
		class UsingComputationInAccessors
		{
			public static void Main(String[] arg)
			{
				PropertyClass propertyObject = new PropertyClass();
				int fieldValue;
				fieldValue = propertyObject.MyValue;
				Console.WriteLine("MyValue: " + fieldValue);
				
				propertyObject.MyValue = 90;
				fieldValue = propertyObject.MyValue;
				Console.WriteLine("MyValue: " + propertyObject.MyValue);
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment