Не понимаю приведение типов и/или поиск членов в C#
От: minorearth  
Дата: 22.07.10 19:44
Оценка:
        class Foo
        {
            private long mData;

            public static implicit operator uint( Foo c )
            {
                return ( uint )c.mData;
            }
            
            public static implicit operator int( Foo c )
            {
                return ( int )c.mData;
            }

            public static implicit operator ushort( Foo c )
            {
                return (ushort)c.mData;
            }

            public static implicit operator sbyte( Foo c )
            {
                return ( sbyte )c.mData;
            }
        }


Почему при вызове:
Console.Write(new Foo());

Будет вызвано неявное преобразование:
public static implicit operator int( Foo c )


А если его закоментить то будет ошибка компиляции:
Ambiguous user defined conversions 'ConsoleModule.ConsoleUI.Foo.implicit operator sbyte(ConsoleModule.ConsoleUI.Foo)' and 'ConsoleModule.ConsoleUI.Foo.implicit operator ushort(ConsoleModule.ConsoleUI.Foo)' when converting from 'ConsoleModule.ConsoleUI.Foo' to 'int'
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.