Why can't I implement an internal interface in an internal class?
internal interface IDefinition
{
string GetValueAsString(string property);
}
internal sealed class DefinitionArray : IDefinition
{
internal string GetValueAsString(string property)
{
return m_definitionRows
.Select(o => o.GetValueAsString(property))
.FirstOrDefault();
}
}
§3.5.6 of the C# 6.0 Language Specification states:
Interface members implicitly have
public
declared accessibility. No access modifiers are allowed on interface member declarations.
So what you 'theoretically' have is
internal interface IDefinition
{
public string GetValueAsString(string property);
}
But this is not a problem, since (§3.5.2):
The accessibility domain of a nested member
M
declared in a typeT
within a programP
is defined as follows (noting thatM
itself may possibly be a type):
- If the declared accessibility of
M
ispublic
, the accessibility domain ofM
is the accessibility domain ofT
.
So the accessibility of the member is equivalent as it would have been declared as internal
.
The members that make up the Interface's implementation must be public. Even if they are public since the class is internal it's only available to the proper assembly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.