Friday, 1 September 2017

C# program example to implement the use of Properties

C# program example to use of Properties in C# program

Program

using System;
class Number
    {
        int num;
        public int anum // Property Declaration
        {
             Get
              {


                return num;
            }
             set
            {
                num = value;
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Number n = new Number();
            int b;
            Console.WriteLine("Enter Number: ");
             b = Convert.ToInt32(Console.ReadLine());
             n.anum = b; // Invoke Set Property
             int a = n.anum; // Invoke Get Property
             Console.WriteLine("Answer: {0}", a);
        }

     } 

Output


0 comments:

Post a Comment