Reputation: 317
I have a class Shoes
with a bool property to check if shoes are secondhand or not.
class Shoes
{
private bool secondhand;
public bool IsSecondHand
{
get { return secondhand; }
set
{
if (value == ) //don't know what to use here
{
value = false;
}
else
{
//is true
}
}
}
}
My intention is to use this class (separate file) with a WPF window and using a checkbox
that when checked makes my bool true, otherwise is false. I need to preserve the format get {} set {}. The problem is that this proprety should "work" even without the WPF part.
Upvotes: 1
Views: 288
Reputation: 2623
Just simply do:
set
{
secondhand = value;
}
Or, as @JFM suggests, you can simply use an auto property and you no longer need to explicitly declare the backing field:
public bool IsSecondHand {get; set;}
Upvotes: 7