I try to declar this statement:
private static int[] MyArr = {0x243F6A88, 0x85A308D3, 0x13198A2E};
And got this error
Cannot implicitly convert type 'uint' to 'int'
What wrong am I
Thank
I try to declar this statement:
private static int[] MyArr = {0x243F6A88, 0x85A308D3, 0x13198A2E};
And got this error
Cannot implicitly convert type 'uint' to 'int'
What wrong am I
Thank
Cannot implicitly convert type 'uint' to 'int'
soanfu
private static int[] MyArr = {0x243F6A88, unchecked((int)0x85A308D3), 0x13198A2E};
niroshanonline
Simply, the value you're attempting to assing to an int value exceed it's "range" capacity.
Integral values expressed using hexadecimal notation are interpreted as UNSIGNED values.
You can use an unchecked explicitly cast or choose a wider type, depending on your needs.
Ri-Karou
OK its work
Thank you very much
Sergey Astapov
Hexadecimal constant is interpreted as unsigned integer, you need to add casting:
private static int[] MyArr = {(int)0x243F6A88, (int)0x85A308D3, (int)0x13198A2E};
tcarff
johnTheDeveloper
Not necessarily. The type depends on the value you specify. The default type rules for numeric literals are the same whether you use decimal or hexadecimal representation.