title: How to structure the code to return certain members only
body: <p>I would like to ask how can I structure the code so that when user (main program) indicates no apple (<code>hasApple = false</code>), user will not be able to access <code>fruitMenu.Apple</code> or <code>fruitMenu.ApplePrice</code>.</p>
  <p>I wanna make the program to behave in a scenario that if there is not apple, then there won't be apple and price of apple property for user to select.</p>
  <pre><code>using System;
  
  namespace ConsoleApplication
  {
      public class Menu
      {
          public class Fruit
          {
              public string Apple { get; set; }
              public double ApplePrice { get; set; }
              public string Orange { get; set; }
              public double OrangePrice { get; set; }
  
              // Constructor
              public Fruit(string apple, double applePrice, string orange, double orangePrice)
              {
                  this.Apple = apple;
                  this.ApplePrice = applePrice;
                  this.Orange = orange;
                  this.OrangePrice = orangePrice;
              }
          }
  
          public bool HasApple { get; set; }
          public bool HasOrange { get; set; }
  
          public Fruit GetMenu()
          {
              string Apple;
              double ApplePrice;
              if (HasApple)
              {
                  Apple = &quot;Apple&quot;;
                  ApplePrice = 5;
              }
              else
              {
                  Apple = &quot;No Apple&quot;;
                  ApplePrice = double.NaN;
              }
  
              string Orange;
              double OrangePrice;
              if (HasOrange)
              {
                  Orange = &quot;Orange&quot;;
                  OrangePrice = 5;
              }
              else
              {
                  Orange = &quot;No Orange&quot;;
                  OrangePrice = double.NaN;
              }
  
              Fruit allFruits = new Fruit(Apple, ApplePrice, Orange, OrangePrice);
              return allFruits;
          }
  
          // Constructor
          public Menu(bool hasApple, bool hasOrange)
          {
              this.HasApple = hasApple;
              this.HasOrange = hasOrange;
          }
      }
  
      public class Program
      {
          static void Main(string[] args)
          {
              Menu menu = new Menu(true, false);            
              Menu.Fruit fruitMenu = menu.GetMenu();
              Console.Write(fruitMenu.Apple);
              Console.Write(&quot;\t&quot;);
              Console.WriteLine(fruitMenu.ApplePrice);
              Console.Write(fruitMenu.Orange);
              Console.Write(&quot;\t&quot;);
              Console.WriteLine(fruitMenu.OrangePrice);
              Console.ReadKey();
          }
      }
  }
  </code></pre>