Console C#.Net Tutorial

Visual Studio.NET IDE

Define C#.NET

C# Comment

C# Variables

C# Data Types

C# Escape Sequence

C# Operators

Format String

Operator Precedence

C# Keywords

Constant Variable

Type Conversion

Flow Control

C# Arrays

C# Character

C# Strings

User-Define Methods

Variable Scope

C# Enumerations

C# Structure

C# Exception Handling

Object Oriented Programming

C# Classes

Constructor & Destructor

C# Inheritance

C# Polymorphism

C# Operator Overloading

C# Method Overriding

C# Interface

Abstract Classes & Methods

Sealed Classes, Methods

C# Properties

C# Indexer

C# Delegates

C# Generics

C# Collection

C# ArrayList

C# Stack

C# Queue

C# HashTable

C# SortedList

Page Stats

Visitor: 195

C#.Net Properties

Properties is use to access the private fields to read or write their values. A property consists of a get or set declaration, or both. A property can be read-write property, read-only property, or a write only property, according to the presence or absence of the get and set accessors. If both are present the property is read-write property. If only get is present it’s a read only property. And if only set is present it’s a write-only property.
The get is a parameter less method with a return value, and use to invoke the value of a private field to compute.
The set is use to assign a value of a private field.

class ex
{
	private int rollno;
	public int RollNo
	{
		get
		{
			return rollno;
		}
		set
		{
			rollno = value;
		}
	}
}
class Program
{
	static void Main(string[] args)
	{
		ex obj = new ex();
		obj.RollNo = 100;
		Console.WriteLine("Rollno=" + obj.RollNo);
		Console.Read();
	}
}
Updated: 07-Feb-19