C # Array returns a value that is not in it

I am learning C # and following some simple tutorials. I have a problem and I don’t understand what is happening. Does my Visual Studio interrupt?

I have:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Learning_C_Sharp { class Program { static void Main(string[] args) { int[] myNumbers = { 10, 20, 30, 40, 50 }; for (int i = 0; i < myNumbers.Length; i++) Console.WriteLine(myNumbers[i]); //Console.WriteLine(myNumbers[0]); Console.Read(); } } } 

I should get the result 10, 20, 30, 40, 50. However, I get 224, since my first number returned instead of 10, regardless of what I set the first number for.

Is my visual studio just broken?

Since then I have uninstalled and reinstalled unchanged. Created a new project and manually entered the code without changes. As long as the array is int, the first value is returned as 224. Also it takes the math, if I say to return the value and add one, then I get 225.

Screenshot to display debug version.

Screenshot of VS showing debug

Additional changes:

I split it into bare bones and no matter how I do it, I still get the same results.

I uninstalled, reinstalled, used Revo Uninstaller to completely destroy VS. Tuesday. I am going to update my computer if someone has no idea.

+5
source share
1 answer

I cannot comment on the actual solution, but it seems to be a quirk dedicated to VS Community 2017. I am on Pro 2017 right now and the same code does not reproduce the error. I am going to write this down to Microsoft error. There seem to be workarounds, however the main problem in itself appears for all intentions to be a glitch specific to this version of VS. If anyone else cannot provide better information about this, I say that it is closed due to Microsoft crash.

0
source

Source: https://habr.com/ru/post/1267302/


All Articles