Russell Mangel wrote:
You have a MsgFile object and it does not implement INoteItem, so
you can not cast to it.
If you has has a NoteItem object, then you could have done it.
Arne
Can anyone tell me *why* I can't cast to INoteItem from IMsgFile?
All interfaces are Explicit. INoteItem derives from MsgFile, not IMsgItem.
Why doesn't this code work? What is the rule I don't understand.
Please don't change the code, just answer my question.
All interfaces are Explicit. INoteItem derives from MsgFile, not IMsgItem.
Why doesn't this code work? What is the rule I don't understand.
Please don't change the code, just answer my question.
using ( MsgFile m = new MsgFile( ) )
{
INoteItem n = m as INoteItem;
>
if ( n == null )
{
Console.WriteLi ne( "Why can't I cast to INoteItem." );
}
{
INoteItem n = m as INoteItem;
>
if ( n == null )
{
Console.WriteLi ne( "Why can't I cast to INoteItem." );
}
public interface INoteItem
{
{
internal class NoteItem: MsgFile, INoteItem
{
{
public interface IMsgFile: IDisposable
{
{
public class MsgFile : IDisposable, IMsgFile
{
{
you can not cast to it.
If you has has a NoteItem object, then you could have done it.
Arne
Comment