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
  1. Home
  2. General Programming
  3. C#
  4. What is an instance variable and how do you declare one?

What is an instance variable and how do you declare one?

Scheduled Pinned Locked Moved C#
question
6 Posts 3 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.
  • N Offline
    N Offline
    Nathan Revka
    wrote on last edited by
    #1

    I need to create the private instance variable savingsBalance, which includes the amount the saver has on deposit, and the saver's first and last name.

    M C 2 Replies Last reply
    0
    • N Nathan Revka

      I need to create the private instance variable savingsBalance, which includes the amount the saver has on deposit, and the saver's first and last name.

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      You can use a class, struct or 3 variables/properties declared private.

      private class SavingsBalance()
      {
      public string FirstName {get; set;}
      }

      Never underestimate the power of human stupidity RAH

      N C 2 Replies Last reply
      0
      • M Mycroft Holmes

        You can use a class, struct or 3 variables/properties declared private.

        private class SavingsBalance()
        {
        public string FirstName {get; set;}
        }

        Never underestimate the power of human stupidity RAH

        N Offline
        N Offline
        Nathan Revka
        wrote on last edited by
        #3

        Wait a minute, aren't you creating a class and not a variable?

        M 1 Reply Last reply
        0
        • N Nathan Revka

          Wait a minute, aren't you creating a class and not a variable?

          M Offline
          M Offline
          Mycroft Holmes
          wrote on last edited by
          #4

          Sure, that example - you can create a private class inside another class. Or use 3 private variables or use a struct.

          Never underestimate the power of human stupidity RAH

          1 Reply Last reply
          0
          • N Nathan Revka

            I need to create the private instance variable savingsBalance, which includes the amount the saver has on deposit, and the saver's first and last name.

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            I think you need to talk to your teacher. It sounds like you're struggling with some real basics.

            Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

            1 Reply Last reply
            0
            • M Mycroft Holmes

              You can use a class, struct or 3 variables/properties declared private.

              private class SavingsBalance()
              {
              public string FirstName {get; set;}
              }

              Never underestimate the power of human stupidity RAH

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              He seems below to be saying he wants to store a string that contains the name and the balance. He actually had the code to do that posted.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              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