Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Problem with properties???

Problem with properties???

Scheduled Pinned Locked Moved C#
helpvisual-studioquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    richiemac
    wrote on last edited by
    #1

    Hi all, I'm declaring a property... public int Number () { get { return myInt; } set { myInt = value; } } and I'm getting a build error. The complaint is coming from the get and set keywords, it is asking for a semi-colon (;) to be placed after each. I also believe that value should be a keyword (i.e. highlighted by the ide) which it is not. Can anyone help because I thought this was pretty straightforward.

    L M S R 4 Replies Last reply
    0
    • R richiemac

      Hi all, I'm declaring a property... public int Number () { get { return myInt; } set { myInt = value; } } and I'm getting a build error. The complaint is coming from the get and set keywords, it is asking for a semi-colon (;) to be placed after each. I also believe that value should be a keyword (i.e. highlighted by the ide) which it is not. Can anyone help because I thought this was pretty straightforward.

      S Offline
      S Offline
      Sean Michael Murphy
      wrote on last edited by
      #2

      richiemac wrote:

      public int Number ()

      Properties are declared without the brackets. The compiler thinks you're trying to declare a function. Should be:

      public int Number {
         get {return MyInt;}
         set {myInt = value;}
      }

      Share and enjoy. Sean

      1 Reply Last reply
      0
      • R richiemac

        Hi all, I'm declaring a property... public int Number () { get { return myInt; } set { myInt = value; } } and I'm getting a build error. The complaint is coming from the get and set keywords, it is asking for a semi-colon (;) to be placed after each. I also believe that value should be a keyword (i.e. highlighted by the ide) which it is not. Can anyone help because I thought this was pretty straightforward.

        M Offline
        M Offline
        Mehdy Khoshrou
        wrote on last edited by
        #3

        public int Number { get { return myInt; } set { myInt = value; } } try this.

        1 Reply Last reply
        0
        • R richiemac

          Hi all, I'm declaring a property... public int Number () { get { return myInt; } set { myInt = value; } } and I'm getting a build error. The complaint is coming from the get and set keywords, it is asking for a semi-colon (;) to be placed after each. I also believe that value should be a keyword (i.e. highlighted by the ide) which it is not. Can anyone help because I thought this was pretty straightforward.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Properties don't need brackets ( and ) in the method header regards

          1 Reply Last reply
          0
          • R richiemac

            Hi all, I'm declaring a property... public int Number () { get { return myInt; } set { myInt = value; } } and I'm getting a build error. The complaint is coming from the get and set keywords, it is asking for a semi-colon (;) to be placed after each. I also believe that value should be a keyword (i.e. highlighted by the ide) which it is not. Can anyone help because I thought this was pretty straightforward.

            R Offline
            R Offline
            richiemac
            wrote on last edited by
            #5

            Thanks guys! Knew it was something trivial.:doh:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups