Accessing Property External Class C# with Example



Accessing Property External Class C# with Example

 	using System;

	namespace CSharpClass{
		class PropertyClass
		{
			private int TheRealValue; 		// Field: memory allocated
			public int MyValue 				// Property: no memory allocated
			{
				set{ TheRealValue = value; }
				get{ return TheRealValue; }
			}
			
			class AccessingPropertyExternalClass
			{
				public static void Main(String[] arg)
				{
					PropertyClass propertyObject = new PropertyClass();
					int fieldValue;
					fieldValue = propertyObject.MyValue;	//Get Field Value via Property's set Accessor
					Console.WriteLine("MyValue: " + fieldValue);
					
					propertyObject.MyValue = 100; 		//Set Field Value via Property's set Accessor
					fieldValue = propertyObject.MyValue;
					Console.WriteLine("MyValue: " + propertyObject.MyValue);
				}
			}
		}
	}
 

0 Comment's

Comment Form

Submit Comment