What is properties:
Why use Properties?
//A simple program to implement property
//using c#
using System;
class company
{
public void interview_sch()
{
Console.WriteLine ( "your interview is schedule" );
}
}
class candidate
{
private string skills;
public string can_skills // This
{ // is
get //
{ // P
return skills; //retrieve // R
} // O
// P
set // E
{ // R
skills = value; //assign // T
} // Y
} //
}
class consultant
{
public static void Main()
{
candidate anil = new candidate();
anil.can_skills = "java";
string s = anil.can_skills;
if (s == "c")
{
company c = new company();
c.interview_sch();
}
else
{
Console.WriteLine ( "your criteria deoesn't match" );
}
}
}
- Properties are like data fields, but have logic behind them
- From the outside, they look like any other member variable
- Defined like a field, with 'get' and 'set' code added
- Can use access modifiers like fields and methode can
Why use Properties?
- properties can be calculated on-the-fly
- provide complete control over data field access
- Properties promote the idea of encapsulation
//A simple program to implement property
//using c#
using System;
class company
{
public void interview_sch()
{
Console.WriteLine ( "your interview is schedule" );
}
}
class candidate
{
private string skills;
public string can_skills // This
{ // is
get //
{ // P
return skills; //retrieve // R
} // O
// P
set // E
{ // R
skills = value; //assign // T
} // Y
} //
}
class consultant
{
public static void Main()
{
candidate anil = new candidate();
anil.can_skills = "java";
string s = anil.can_skills;
if (s == "c")
{
company c = new company();
c.interview_sch();
}
else
{
Console.WriteLine ( "your criteria deoesn't match" );
}
}
}
No comments:
Post a Comment