You can set the values of the enums so you never have a zero value.
You can give each card a value that you want.
You can have repeating values.
You can cast the enums as integers or other numeric types.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
Perhaps this will help you out:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Enumtest
{
class Program
{
public enum KortVerdi { To = 2, Tre = 3, Fire = 4, Fem = 5, Seks = 6, Sju = 7, Åtte = 8, Ni = 9, Ti = 10, Knekt = 10, Dame = 10, Konge = 10, Ess = 11 };
static void Main(string[] args)
{
System.Array intAr = Enum.GetValues(typeof(KortVerdi));
string str = intAr.GetValue(9).ToString(); //the variable str will contain "Knekt"
int KortVal = (int)KortVerdi.Knekt; // KortVal will contain the int value 10
Console.ReadLine();
}
}
}
Success!
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
I like @ddanbe's example and it might work for your needs.
You could also use a dictionary depending on how much data you will have.
Since your "key" might have repeating values, I recommend an ILookup or a List of KeyValuePairs.
Here's an example:
using System;
using System.Collections.Generic;
using System.Linq;
namespace DW_409885_CS_CON
{
using KVP_I2S = KeyValuePair<int, string>;
using LST_KVP_I2S = List<KeyValuePair<int, string>>;
class Program
{
static void Main(string[] args)
{
LST_KVP_I2S lst_kvp_i2sCards = new LST_KVP_I2S()
{
new KVP_I2S(2, "Two of Spades"),
new KVP_I2S(2, "Two of Hearts"),
new KVP_I2S(2, "Two of Clubs"),
new KVP_I2S(2, "Two of Diamonds"),
new KVP_I2S(3, "Three of Spades"),
new KVP_I2S(3, "Three of Hearts"),
new KVP_I2S(4, "Three of Clubs"),
new KVP_I2S(4, "Three of Diamonds"),
new KVP_I2S(11, "Ace of Spades"),
new KVP_I2S(11, "Ace of Hearts"),
new KVP_I2S(11, "Ace of Clubs"),
new KVP_I2S(11, "Ace of Diamonds")
};
// Show the names of the cards that are less than an Ace
foreach (KVP_I2S kvp in lst_kvp_i2sCards.Where(i => i.Key < 11))
{
Console.WriteLine(kvp.Value);
}
}
}
}
If this is too complex, please let me know.
You could also use a class to hold each card and the properties of the class will hold the necessary strings and values.
thines01
Postaholic
2,424 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402