Link to home
Start Free TrialLog 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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Modifier1000

ASKER

Thanks!