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 CaptainJack, 05-29-2026, 05:09 AM
      0 responses
      217 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 05-29-2026, 12:02 AM
      0 responses
      133 views
      0 likes
      Last Post CaptainJack  
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      147 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      233 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      192 views
      0 likes
      Last Post CarlTrading  
      Working...
      X