Link to home
Create AccountLog in
Avatar of Modifier1000
Modifier1000Flag for United States of America

asked on

C# Automatic Properties explanation?

Hello Experts,

I'm working some tutorials learning C# and came across Automatic Properties.  Now, I'm not quite sure how they are supposed to work.
Main Class code
            myExample myEx = new myExample(); 
            int i = myEx.CurrentValue;

            Console.WriteLine(i);
            Console.ReadLine();

Open in new window

Class with private var code
    class myExample
    {
        private int someVal = 38;
        public int CurrentValue
        {
            get { return someVal; }
            set { someVal = value; }
        }
    }

Open in new window

When I run the code, I get 38 in the console.  But how do I turn the Class with private var code to an automatic property returning 38 to the console?
ASKER CERTIFIED SOLUTION
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Modifier1000

ASKER

Thanks!