2. • C# Properites doesn't have storage location. C# Properites are extension
of fields and accessed like fields.
• The Properties have accessors that are used to set, get or compute their
values.
• Usage of C# Properties
• C# Properties can be read-only or write-only.
• We can have logic while setting values in the C# Properties.
• We make fields of the class private, so that fields can't be accessed from
outside the class directly. Now we are forced to use C# properties for
setting or getting values.
3. • Properties are named members of classes, structures, and interfaces.
Member variables or methods in a class or structures are called Fields.
Properties are an extension of fields and are accessed using the same
syntax. They use accessors through which the values of the private fields
can be read, written or manipulated.
• Properties do not name the storage locations. Instead, they
have accessors that read, write, or compute their values.
• For example, let us have a class named Student, with private fields for
age, name, and code. We cannot directly access these fields from outside
the class scope, but we can have properties for accessing these private
fields.
• Accessors
• The accessor of a property contains the executable statements that helps
in getting (reading or computing) or setting (writing) the property. The
accessor declarations can contain a get accessor, a set accessor, or both.
4. • using System;
• public class Employee
• { private string name;
• public string Name
• { get
• { return name; }
• set
• { name = value; } } }
• class TestEmployee{
• public static void Main(string[] args)
• { Employee e1 = new Employee();
• e1.Name = "Sonoo Jaiswal";
• Console.WriteLine("Employee Name: " + e1.Name); } }
5. For more visit our website www.siri-kt.blogspot.com
Thanks for
Watching
More Angular JS TutorialsMore C sharp (c#) tutorials