Saturday, February 20, 2016

Lambda getsetter which only gets one thing in C#?

If SumpremeCourtJustice were an enum you could have...

public SumpremeCourtJustice VacantSeat => SumpremeCourtJustice.Scalia;

 
 

This is basically just like this...

public const SumpremeCourtJustice VacantSeat = SumpremeCourtJustice.Scalia;

 
 

...however the first thing could be augmented with virtual and/or override keywords which do not jive with the const keyword. ...But, what if the parent is an abstract class and just has something like this:

public abstract SumpremeCourtJustice VacantSeat { get; }

 
 

If there is no default setting, then the overriding looks like:

public override SumpremeCourtJustice VacantSeat { get; } =
      SumpremeCourtJustice.Scalia;

No comments:

Post a Comment