i wasnt quite sure how word question.. anyway, here's trying do.
let's have 2 enums:
enum test1 : byte { byte1 = 0x00; byte2 = 0x01; byte3 = 0x02; } enum test2 : byte { byte1 = 0x10; byte2 = 0x20; byte3 = 0x30; } i aware i'm not able group enums inside of enum, trying describe trying do.
i want able group them, like:
enum testgroup { test1, test2 } and after, able call , reference them such:
void main() { runtest(testgroup.test2); } void runtest(testgroup group) { console.writeline(group.byte2); } basically, method print byte2 whichever enum pass parameter.
so, example, pass test1 parameter runtest, prints value of byte2, being 0x01, or pass test2 parameter, , prints byte2, being 0x20.
what way go this?
rather using actual enum types, can create own types emulate enum pattern degree, having private constructor , fixed number of static fields each initialized appropriate value. lets have functions enum doesn't need encapsulate single integer type value.
public class group { private group(byte a, byte b, byte c) { = a; b = b; c = c; } public byte { get; private set; } public byte b { get; private set; } public byte c { get; private set; } public static readonly group 1 = new group(0, 1, 2); public static readonly group 2 = new group(8, 16, 24); } you can have method accepting group, in can pass in group.one or group.two it.
Comments
Post a Comment