Having looked at the source code for Microsoft.VisualBasic.Strings.Chr() , I see the following (which I simplified for this post by removing exception handling):
It seems that for 7-bit values, Convert.ToChar(CharCode) returned, which I suppose the compiler is smart enough to conclude a constant, while for 8-bit values, the current CodePage culture is used, which will give different computer-based results, on which code works, and therefore can not be a constant.
Update: I tried to replicate the situation in a method that I wrote myself, but I canβt, which suggests that the compiler itself may have a special rule for evaluating constant expressions.
Private Function ConstOrNot(input As Int32) As Int32 If input = 3 Then Return 7 Return (New Random).Next End Function Const intC1 As Int32 = ConstOrNot(3)
(However, ConstOrNot() exists in the same assembly as the code that calls it, so this might not work.)
source share