namespace Tester
{
public class MyClass
{
private int _age;
public int Age
{
set
{
this._age = value;
}
}
} // MyClass ends here.
class Program
{
static void Main()
{
MyClass MC = new MyClass();
int i = MC.Age = 19;
Console.WriteLine(i);
Console.ReadLine();
}
}
}
I have only set accessor but i can still read the value of age. how i can implement write only property which cannot be read.

Chris A10 reputationPosted Jul 12, 2017, 2:41 PM EDT
Sarmad Rehman14 reputationPosted Jul 13, 2017, 3:52 AM EDT
Tapan PatelRank #614 · 3.9K reputationPosted Jul 13, 2017, 5:45 AM EDT
Sarmad Rehman14 reputationPosted Jul 14, 2017, 9:33 AM EDT
namespace Tester
{
public class MyClass
{
private int _age;
public int Age
{
private get
{
return this._age;
}
set
{
this._age = value;
}
}
} // MyClass ends here.
class Program
{
static void Main()
{
MyClass MC = new MyClass();
int i = MC.Age = 19;
//Console.WriteLine(MC.Age);
Console.WriteLine(i);
Console.ReadLine();
}
}
Chris A10 reputationPosted Jul 14, 2017, 4:05 PM EDT