หมายเหตุ
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลอง ลงชื่อเข้าใช้หรือเปลี่ยนไดเรกทอรีได้
การเข้าถึงหน้านี้ต้องได้รับการอนุญาต คุณสามารถลองเปลี่ยนไดเรกทอรีได้
Shift operations in generic math now have consistent behavior across all built-in integer types.
Previous behavior
Previously, the behavior when utilizing generic math to perform a shift on a T could differ based on the type. In some cases, it appropriately masked the shift amount by sizeof(T) - 1. And in other cases, there was no masking. This meant that "overshifting" (such as shifting a byte by 8) could result in different answers than expected.
New behavior
The implementations were updated to mask the shift amount, as appropriate, to ensure consistent behavior across all built-in integer types and with the behavior documented by the System.Numerics.IShiftOperators<TSelf,TOther,TResult> interface.
Version introduced
.NET 10
Type of breaking change
This change is a behavioral change.
Reason for change
The behavior differed from the designed behavior due to a difference in how masking works for small integer types in C#.
Recommended action
Update any code that relies on the previous inconsistent behavior to ensure it works with the new consistent behavior.
Affected APIs
operator <<operator >>operator >>>forbyte,char,sbyte,short, andushortwhen used via generic math, which requires aTconstrained towhere T : IShiftOperators<T, int, T>or a similar interface.