i am having a big question over the below line my project.Please help me some to understand its significance.Please note that i know what is properties.
properties- to access private elements in our application by using a public access or its a encapsulation of sensitive information
Auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects. When you declare a property as shown in the following example, the compiler
creates a private, anonymous backing field that can only be accessed through the property's get and set accessors.
Sometimes properties also holds some behavior or validation (for eg.) like if you are giving a property named
AGE of datatype INT then its obvious you won't pass string values.So to make sure correct values are being passed we use get and set.
ssramvinay.83
What is the use of the below line?
publicstringName { get;
set; }
It means you are defining a property named Name.Here you are simply passing the values without any check.An example would be something like below:
class TimePeriod
{
private double seconds;
public double Hours
{
get { return seconds / 3600; }
set { seconds = value * 3600; }
}
}
Member
43 Points
68 Posts
What is properties in c#?
Jan 05, 2015 01:01 AM|ssramvinay.83|LINK
Hi,
i am having a big question over the below line my project.Please help me some to understand its significance.Please note that i know what is properties.
properties- to access private elements in our application by using a public access or its a encapsulation of sensitive information
My queries are :
Why we are given blank getset values?
What is the use of the below line?
public
string
Name {
get
;
set
; }
All-Star
120146 Points
27989 Posts
Moderator
MVP
Re: What is properties in c#?
Jan 05, 2015 02:01 AM|ignatandrei|LINK
http://msdn.microsoft.com/en-us/library/bb384054.aspx
Star
13653 Points
5480 Posts
Re: What is properties in c#?
Jan 05, 2015 02:16 AM|Ashim Chatterjee|LINK
Hello,
Sometimes properties also holds some behavior or validation (for eg.) like if you are giving a property named AGE of datatype INT then its obvious you won't pass string values.So to make sure correct values are being passed we use get and set.
It means you are defining a property named Name.Here you are simply passing the values without any check.An example would be something like below:
Member
43 Points
68 Posts
Re: What is properties in c#?
Jan 05, 2015 05:16 AM|ssramvinay.83|LINK
Got some precise details about Properties
In C# 2.0 version,we used to write the below code
But in C#3.0,we used to write as below.
Because in C#3.0,the compiler creates private fields(beloe code in background) which are accessed through the property's get and set assessors. :)