Vorrei trovare un modo per verificare se un insieme di valori è contenuto nella mia variabile.Impostare in enum per C#
[Flags]
public enum Combinations
{
Type1CategoryA = 0x01, // 00000001
Type1CategoryB = 0x02, // 00000010
Type1CategoryC = 0x04, // 00000100
Type2CategoryA = 0x08, // 00001000
Type2CategoryB = 0x10, // 00010000
Type2CategoryC = 0x20, // 00100000
Type3 = 0x40 // 01000000
}
bool CheckForCategoryB(byte combinations)
{
// This is where I am making up syntax
if (combinations in [Combinations.Type1CategoryB, Combinations.Type2CategoryB])
return true;
return false;
// End made up syntax
}
Sono un trapianto in .NET di Delphi. Questo è un codice abbastanza facile da scrivere in Delphi, ma non sono sicuro di come farlo in C#.
Se avete intenzione di fare questo, sarebbe anche una buona idea dichiarare "public enum Combinations: byte'. –
Heh, +1 da parte mia per essere abbastanza veloce da ottenere sia la risposta che ottenere 10 upvotes prima di pubblicare il mio :) – slugster