Consider an interface and a method that returns an object that implements this interface:
interface ILoggedData
{
public int Id {get;}
public string Description {get;}
}
class LoggedDataReader
{
public ILoggedData GetLoggedData()
{
...
LoggedData loggedData = new LoggedData(...);
return loggedData;
}
private class LoggedData : ILoggedData
{
...
public int Id {get; set;}
public string Description {get; set;}
}
}
So LoggedDataReader.GetLoggedData
creates an object of private class LoggedData
and returns the interface ILoggedData
.
I assumed that the conversion from LoggedData to the interface doesn't do anything. You can regard it as a limitation for the compiler: "You can only use these getter properties". I assumed that just the reference to the loggedData object is returned, and interpreted as the reference to the interface.
Is this correct, or does the type conversion from object to interface actually do anything?