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 APosted Jul 14, 2017, 8:05 PM
Sarmad RehmanPosted Jul 14, 2017, 1:33 PM
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();
}
}
Tapan PatelPosted Jul 13, 2017, 9:45 AM
Sarmad RehmanPosted Jul 13, 2017, 7:52 AM
Chris APosted Jul 12, 2017, 6:41 PM