CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Post How to turn this code into properties?

    public class Answer
    {
    public Answer(string p, bool c)
    {
    Prompt = p;
    Correct = c;
    }
    public string Prompt;
    public bool Correct;
    }

  2. #2
    Ejaz's Avatar
    Ejaz is offline Elite Member Power Poster
    Join Date
    Jul 2002
    Location
    Lahore, Pakistan
    Posts
    4,211

    Re: How to turn this code into properties?

    This is VC++ board. You are posting in the wrong forum again. This is right place for C# questions.

  3. #3
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: How to turn this code into properties?

    [ Moved thread ]

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to turn this code into properties?

    Two ways.
    Using 'regular' properties:
    Code:
    public class Answer
    {
      public Answer(string p, bool c)
      {
        Prompt = p;
        Correct = c;
      }
      
      public string Prompt
      {
        get { return _prompt; }
        private set { _prompt = value; }
      }
    
      public bool Correct; 
      {
        get { return _correct; }
        private set { _correct = value; }
      }
      private string _prompt;
      private string _correct;
    }
    Using autoproperties:
    Code:
    public class Answer
    {
      public Answer(string p, bool c)
      {
        Prompt = p;
        Correct = c;
      }
      
      public string Prompt { get; private set; }
      public bool Correct { get; private set; }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured