C# How to use get, set and use enums in a class -


i have program use class store settings. need use set , functions change , store settings. have tried this, , don't work. can me one?

    private enum _difficulty { easy, normal, hard };      public void setdifficulty(difficulty)     {         _difficulty = difficulty;     }      public enum getdifficulty()     {         return _difficulty;     } 

is there no way use enums in class get , set?

i need bool , int.

there several things wrong here:

  • your enum private, methods public. therefore can't make methods return type enum type, or have parameters type
  • your setdifficulty method has parameter of difficulty - meant parameter name or type?
  • your setdifficulty method trying set type rather field
  • your getdifficulty method trying use enum return type, , returning type rather field

basically, seem confused enum declaration declaring - it's not declaring field, it's declaring type (and specifying named values of type are).

i suspect want:

// try not use nested types unless there's clear benefit. public enum difficulty { easy, normal, hard }  public class foo {     // declares property of *type* difficulty, , *name* of difficulty     public difficulty difficulty { get; set; } } 

you can use get/set methods if want make code java instead of c#:

public enum difficulty { easy, normal, hard }  public class foo {     private difficulty difficulty;      public void setdifficulty(difficulty value)     {         difficulty = value;     }      public difficulty getdifficulty()     {         return difficulty;     } } 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -