Explicit interface implementation is a sort of half-way house between public and private: it's public if you're using an interface-typed reference to get at it, but that's the only way of accessing it (even in the same class).
If you're using implicit interface implementation you need to specify it as public because it is a public method you're overriding by virtue of it being in the interface. In other words, the valid code is:
public class Foo : IBar
{
// Implicit implementation
public string GetQueryString()
{
///...
}
// Explicit implementation - no access modifier is allowed
string IBar.GetQueryString()
{
///...
}
}
Personally I rarely use explicit interface implementation unless it's required for things like IEnumerable<T>
which has different signatures for GetEnumerator
based on whether it's the generic or non-generic interface:
public class Foo : IEnumerable<string>
{
public IEnumerator<string> GetEnumerator()
{
...
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator(); // Call to the generic version
}
}
Here you have to use explicit interface implementation to avoid trying to overload based on return type.