string s = "-1"; // или другое отриц. uint u = uint.Parse(s); // uint u = Convert.ToUInt32(s); 

Overflow anyway.

    1 answer 1

    Well, for starters, it's worth reading what uint . There is a range of values from 0 to 4,294,967,295 ( MSDN ). When converting a number outside the range of values ​​to the desired type - the resulting number will be distorted / lost. If you are not worried about the possible loss of value - use an explicit type conversion:

     uint a = 123; int b = (int)a; 
    • Well, for starters, it's worth reading the question. - VPCHR
    • The answer to the question is given. int to uint can also be converted as in my example uint to int .. only with a negative value problems arise .. it is probably worth choosing another type. Well, or I did not understand the question and you should better explain the problem - Volodymyr
    • the number 11111111111111111111111111111110 will be -2 int or 4294967294 uint. The number is represented by 'string' - VPCHR
    • you go beyond the range of values ​​- hence the problem. I don’t remember exactly how the mechanism considers it, but when it reaches the range limit - the compiler resets the value and reads the following numbers from the beginning of the range .... in general, you will not have anything normal with such numbers - you need to use the type with a larger extension .. well or store the number in parts in several variables - Volodymyr