CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
Dictionary<CardValue, int> dict1 = new();
foreach(CardValue x in Enum.GetValues(typeof(CardValue)))
dict1.Add(x, 0);
Console.WriteLine($"dict1: {String.Join(", ", dict1)}");
Dictionary<CardValue, int> dict2 = Enum.GetValues(typeof(CardValue))
.Cast<CardValue>()
.ToDictionary(x => x, x => 0);
Console.WriteLine($"dict2: {String.Join(", ", dict2)}");
}
public enum CardValue
{
Ace = 1,
Two = 2,
Three = 3,
Four = 4,
Five = 5,
Six = 6,
Seven = 7,
Eight = 8,
Nine = 9,
Ten = 10,
Jack = 11,
Queen = 12,
King = 13
}
}