Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Enum Issue

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Custom Enum Issue

    Hello all,
    I am trying to create a enum as a user input to allow the user to select an option which would switch an integer value. The below code prints "1", regardless of which value (NQ or ES) is selected. I'm not sure where I have it wrong here.

    Code:
    switch (asset)
    {
          case AssetName.ES:
          {
                x = 1;
                break;
          }
          case AssetName.NQ:
          {
                x = 2;
                break;
          }​
    }
    
    Print(x);
    Code:
    [Display(Name = "Ticker", GroupName="Inputs")]
    public AssetName Asset
    {
          get { return asset; }
          set { asset = asset; }
    }​
    Code:
    public enum AssetName
    {
        ES,
        NQ
    }​

    #2
    Code:
    [Display(Name = "Ticker", GroupName="Inputs")]
    public AssetName Asset
    {
        get { return asset; }
        set { asset = value; }
    }
    You had,

    asset = asset;

    It should be,

    asset = value;

    -=o=-

    Or you could do this,

    [Display(Name = "Ticker", GroupName="Inputs")]
    public AssetName Asset { get; set; }


    and then use uppercase 'Asset' property everywhere you're
    currently using the lowercase 'asset' variable. Then delete
    the lowercase 'asset' variable, since it's no longer being used.

    Last edited by bltdavid; 05-30-2023, 10:17 PM.

    Comment


      #3
      ahhh, that makes sense. The second option is perfect. Thanks David.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      651 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      370 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      109 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      574 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      577 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X