This is basically a theoretical question: I do not need a practical solution, but when used foreachin MS V C # 2010 with the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] ints = new int[7]{0,0,0,0,0,0,0};
foreach (int i in ints)
{
i = 10;
}
Console.ReadKey();
}
}
}
I get an error that tells me that I cannot change i because it is a variable foreach, now if I wanted to be able to do this simple task in several other ways, but the fact is that I did not see anything in the documentation , which would forbid what I am trying to do, and I think it foreachshould give you the opportunity to change the variable in the list.
Is there something I am missing?
source
share