C sharp lab program for be students, Exams of Engineering

execution steps to run c sharp program in windows

Typology: Exams

2017/2018

Uploaded on 09/04/2018

Spoorthi.Kumar
Spoorthi.Kumar 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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);
}
pf3
pf4

Partial preview of the text

Download C sharp lab program for be students and more Exams Engineering in PDF only on Docsity!

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); } }