example

CSharp · Console

/Program.cs

using System.Linq;
using System;
using System.Collections.Generic;

public class Program
{
	public static void Main()
	{
		// some random entries
		var Match = new Buyer[]{new Buyer()
		{District = "A"}, new Buyer()
		{District = "A"}, new Buyer()
		{District = "D"}, new Buyer()
		{District = "B"}, new Buyer()
		{District = "A"}, new Buyer()
		{District = "A"}, new Buyer()
		{District = "E"}, new Buyer()
		{District = "B"}, new Buyer()
		{District = "C"}, new Buyer()
		{District = "A"}, new Buyer()
		{District = "B"}, new Buyer()
		{District = "A"}, };
		Dictionary<string, int> TempList = new();
		foreach (var VARIABLE in Match)
		{
			var district = VARIABLE.District;
			TempList.TryGetValue(district, out var count);
			
			TempList[district] = count + 1;
		}

		foreach (var kvp in TempList)
		{
			Console.WriteLine($"{kvp.Key} - {kvp.Value}");
		}
	}
}

public class Buyer
{
	public string Name;
	public string District;
	public int Age;
}
;