[nem-en] casts

Ivan Lakhturov lakhturov at gmail.com
Sat Dec 16 21:26:42 CET 2006


Hello Kamil,

yes, this code snippet is working (exception is described):

            b = a;
            b = (B)7;
            try
            {
                // System.InvalidCastException: Unable to cast object of type 'BothOverloadsDefined.A' to type 'BothOverloadsDefined.B'.
                b = (B)a;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

  i can post the whole example, it's similar to that i posted earlier
  so, consuming is ok, c# is going crazy just about explicit downcast

> Did you check the behavior or C# compiler when consuming classes with
> such operator defined?

> 2006/12/16, Ivan Lakhturov <lakhturov at gmail.com>:
>> Hello devel-en,
>>
>>   ok, casts are working as casts (for outside) now
>>
>>   and i checked some things...
>>
>>   so, let's proceed with the next simple question
>>
>>
>>
>>   public class A {}
>>   public class B : A
>>   {
>>     public static @:>(_ : A) : B
>>     {
>>       B()
>>     }
>>   }
>>
>>
>>
>>       def a = A();
>>       def b : B = a :> B;
>>
>>   should it be allowed or not? how d'you think, guys?
>>   (c# prohibits overloading upcasts in B)
>>
>> regards, phantom
>>
>>
>> _______________________________________________
>> https://nemerle.org/mailman/listinfo/devel-en
>>





regards, phantom




More information about the devel-en mailing list