C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/* Accessor method suffers from the following drawbacks:
^ We have to code the accesor methods manually
^ users have to remember that they have to use a accessor methods to work with data members.
*/
namespace Property
{
class Number
{
private int number;// property
public int Anumber
{
get
{
return number;
}
set
{
number = value;
}
}
public class PropertyTest
{
public static void Main(string[] args)
{
Number n=new Number();
n.Anumber=100;
int m=n.number;
Console.WriteLine("Number="+m);
Console.ReadKey();
}
}
}
}
Output:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
/* Accessor method suffers from the following drawbacks:
^ We have to code the accesor methods manually
^ users have to remember that they have to use a accessor methods to work with data members.
*/
namespace Property
{
class Number
{
private int number;// property
public int Anumber
{
get
{
return number;
}
set
{
number = value;
}
}
public class PropertyTest
{
public static void Main(string[] args)
{
Number n=new Number();
n.Anumber=100;
int m=n.number;
Console.WriteLine("Number="+m);
Console.ReadKey();
}
}
}
}
Output:
No comments:
Post a Comment