Actualizar Struct en foreach loop en C #
Tengo este código (C #):
using System.Collections.Generic;
namespace ConsoleApplication1
{
public struct Thing
{
public string Name;
}
class Program
{
static void Main(string[] args)
{
List<Thing> things = new List<Thing>();
foreach (Thing t in things) // for each file
{
t.Name = "xxx";
}
}
}
}
No compilará.
El error es:
Cannot modify members of 't' because it is a 'foreach iteration variable'
Si cambioThing
a unclass
preferible astruct
Sin embargo, sí compila.
Por favor, ¿alguien puede explicar lo que está pasando?