I am going through a LitJSON library. In the code there are lots of segments like
public class JsonData : IJsonWrapper, IEquatable
#region
That's what's called an Explicit Interface Implementation. It is used to expose properties only on instances of the specified interface.
The example you provided above would only expose the Count property if the declared variable happened to be an ICollection type
MSDN
Here's a good use case, think about a Blackjack game, both the Player and Dealer will be dealt two cards.
The dealer will only reveal one card of his hand, whilst you'll be able to see both of yours, so our hand needs a different behaviour dependent on the Interface that the client has specified.
public interface IHand {
List CurrentHand { get; }
}
public interface IDealerHand : IHand {
}
public interface IPlayerHand : IHand {
}
public class Hand : IDealerHand, IPlayerHand{
private List cardsHeld;
// The implementation here will ensure that only a single card for the dealer is shown.
List IDealerHand.CurrentHand { get { return cardsHeld.Take(1); } }
// The implementation here will ensure that all cards are exposed.
List IPlayerHand.CurrentHand { get { return cardsHeld; } }
}