c# - Difference between property Users and IRepository.Users -


i have interface irepository abstract repository. dbcontext class entity framework work first code.

public interface irepository  {     iqueryable<user> users { get; } }  public class repository : dbcontext, irepository {     public dbset<user> users { get; set; }     iqueryable<user> irepository.users { get{ return users; } } } 

i did not understand user property user in repository class.

this code compiles, wonder why.

what interface name before name of property?

this valid syntax, called explicit interface implementation. it's useful in 2 situations:

  • when implement 2 interfaces same method (check link above)
  • when want "hide" implementation detail in sense. in example, if user have dbcontext reference, see dbset<user> property , able access it, on other hand, if give user irepository - see iqueryable<user>, let's hide what's underneath it.

//edit: actually, 1 more usage , used in code well:

  • you can hide methods / properties still implementg them. example, dictionary<k, v> implements icollection<keyvaluepair<k, v>>, it's ought implement method signature: void add(keyvaluepair<k, v> kv), 1 ugly, prefer void add(k key, v value), can't ignore first one. explicit int. impl. can implement first method, hide user (at least long won't cast dictionary icollection).

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -