


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
execution steps to run c sharp program in windows
Typology: Exams
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Properties allow you to control the accessibility of a classes variables, and is the recommended way to access variables from the outside in an object oriented programming language like C#.
A property is much like a combination of a variable and a method - it can't take any parameters, but you are able to process the value before it's assigned to or returned.
A property consists of 2 parts, a get and a set method, wrapped inside the property:
private string color;
public string Color { get { return color; } set { color = value; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Get_Set { class access { // String Variable declared as private private static string name; public void print() { Console.WriteLine("\nMy name is " + name); }
public string Name //Creating Name property { get //get method for returning value { return name; } set // set method for storing value in name field. { name = value; } } }
class Program { static void Main(string[] args) { access ac = new access(); Console.Write("Enter your name:\t"); // Accepting value via Name property ac.Name = Console.ReadLine(); ac.print(); Console.ReadLine(); } } }
Program for record
using System;
((Employee)m1).Name = "Mary"; System.Console.WriteLine("Name in the derived class is: {0}", m1.Name); System.Console.WriteLine("Name in the base class is: {0}", ((Employee)m1).Name); } }