News for hackers. Stuff that matters.
Re:Classes vs. Structs in .NET. How not to teach about perfo... by SideburnsOfDoom on Saturday November 04, 2023 @02:07PM (#38143605)
This is where a well-placed .ToList() is called for, to reify avoid re-evaluating the enumeration.

e.g.

var classes = Names.Select(x => new PersonStruct { Name = x }).ToList();

for (var i = 0; i < classes.Count; i++)

Re:Classes vs. Structs in .NET. How not to teach about perfo... by mxz3000 on Saturday November 04, 2023 @03:43PM (#38144446)
I also believe that an IDE like Rider will complain that the IEnumerable returned by `.Select` is consumed multiple times.
Re:Classes vs. Structs in .NET. How not to teach about perfo... by diarrhea on Saturday November 04, 2023 @03:55PM (#38144538)
Good point! I remember that being a lint in Visual Studio. A very valid one.

In contrast, in Python, initial use exhausts generators. Subsequent iterations turns up empty. A gotcha, but also a way to highlight misuse, as it should show up in testing.

Re:Classes vs. Structs in .NET. How not to teach about perfo... by progmetaldev on Saturday November 04, 2023 @07:29PM (#38146332)
Yes, and both Rider and VS with Resharper will offer a refactor.