.NET Fiddle

CSharp · Console

/Program.cs

using System;
using System.Collections.Generic;
using System.Threading;
using System.Runtime.InteropServices;

public static class Program
{
    public static void Main()
    {
        List<(string DataSetCode, int NumProcessed)> list
            = new() { ("A", 0), ("B", 0), ("C", 0) };
        int index = 1;
        Console.WriteLine($"Before: {String.Join(", ", list)}");

        lock (list)
        {
            var temp = list[index];
            temp.NumProcessed++;
            list[index] = temp;
        }
        Console.WriteLine($"After1: {String.Join(", ", list)}");

        lock (list)
        {
            Span<(string DataSetCode, int NumProcessed)> span = CollectionsMarshal
                .AsSpan(list);
            span[index].NumProcessed++;
        }
        Console.WriteLine($"After2: {String.Join(", ", list)}");

        // Incorrect code, for educational purposes only
        {
            Span<(string DataSetCode, int NumProcessed)> span = CollectionsMarshal
                .AsSpan(list);
            Interlocked.Increment(ref span[index].NumProcessed);
        }
        Console.WriteLine($"After3: {String.Join(", ", list)}");
    }
}
;