0

I have an enum and I need to bind these values to the switch in another class, Help please, I'm confused

public enum GSProccesingType {
    bigCover,
    cover,
    other
}

class Test {
 switch (GSProccesingType){
        case bigCover:
        break;
        case cover:
            break;
        case default:
    }
 }

enter image description here

8
  • what's the confusion ? Commented Sep 4, 2018 at 5:36
  • 1
    Switch takes a value expression, not a type even for the num. Commented Sep 4, 2018 at 5:36
  • 1) You can't have raw statements in a class declaration; they need to be in a method or an initialization block. 2) You have to switch on a value, not on a type. Commented Sep 4, 2018 at 5:37
  • stackoverflow.com/questions/2836286/… maybe this works for you Commented Sep 4, 2018 at 5:38
  • case default: is also a syntax error. Did you mean default: or case other:? Commented Sep 4, 2018 at 5:39

1 Answer 1

0

You'll have to create an object first. Then use that object in switch statement. Like below:

GSProccesingType type = GSProccesingType.cover;.   // type will hold any one of the enum values. Cover is one such value
switch(type){...}

For your example you need to put bigCover in switch

Sign up to request clarification or add additional context in comments.

6 Comments

why .cover if i have in enum 3 values: bigCover, cover and other?
It's an example. The object will hold any one of the enum values
I can not understand .cover And what is this?
For your case bigCover holds the value of the enum. Put that variable in the switch.
@TerletskiyAlexander Perfect example, when you don't read the topic completely and directly jumped into implementation.You should first understand what is ENUM
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.