s

C# properties edit button Edit

author
Rakesh Kumar Sutar | calendar 20 January 2021 | 2109

Introduction

Properties in C# is used to access private variables using get and set method.

Example

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{
    
    class Program
    {
        private string name; // field
        public string Name   // property
        {
            get { return name; }
            set { name = value; }
        }
        static void Main(String[] args)
        {
            Program myObj = new Program();
            myObj.Name = "Rakesh Kumar Sutar";
            Console.WriteLine("     " myObj.Name);
            Console.ReadLine();
        }
    }
}

Output