Cette page n'est pas encore disponible en français, sa traduction est en cours. Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.
When a variable is marked dynamic, the compiler does not validate that the right operand of bitwise or shift operations is valid, which can lead to an unexpected run-time exception. This rule checks that the right operand of bitwise and shift operations is of type int, sbyte, byte, short, ushort, or char.
Input:
dynamicdyn=4;// The next line causes a run-time exception:varshifted=dyn<<2.0;
Output:
Run-time exception (line 6): Operator '<<' cannot be applied to operands of type 'int' and 'double'\
Stack Trace:\
[Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '<<' cannot be applied to operands of type 'int' and 'double']\
at CallSite.Target(Closure , CallSite , Object , Double )\
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)\
at Program.Main()