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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X