Can we do like this in enums

enum myStringEnum {
enumItem1 = "value 1",
enumItem2 = "value 2",
etc
}

i.e.spaces in the string value, I know we can assign int value to enum
but I m not sure whether string values (with spaces) can be assigned to enums.
If no, then can we have some alternative?
Since I want the string values with spaces in enum

Not possible, enum based on just integers int, uint,...

You can extract the name of each element in the enumeration (with ToString) to use that for your name, but you couldn't use an illegal name (like something containing a space) when creating the enum structure.

You would be better off to use a collection of objects of a custom class with a string for the name you need to display and an integer (or any other kind of object) as the 'value'. Then you could use the values of the list items in place of enums. See the Help for "generics" for ways to do that.

This is a typical class for this purpose. Note that it uses a integer for the 'value', but you could change that to an integer, character or whatever else is needed (or just cast the object, if you want to take your chances).

public class NameValuePair {
        string name = "";
        object value = null;

        public NameValuePair(string name, object value) {
            this.name = name;
            this.value = value;
        }

        public string Name { get { return name; } set { name = value; } }
        public object Value { get { return value; } set { this.value = value; } }

        public override string ToString() {
            return name;
        }
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.