Q:

StackOverflowException in property setter

I am new to programming and am currently taking a C# class. I am lost with this weeks assignment. Here is my assignment:
Create a file containing a class “Distance”. Internally distance is kept to an accuracy of 1/64 inch.
Distance must have a private unsigned integer variable “SixtyFourths”, the exact value of this integer should be the count of 1/64th’s of an inch the distance represents.
Create a property “Inches” to get and set Distance from a double value in inches.
Create a property “Feet” to get and set Distance from a double value in feet.
Create a property “Meters” to get and set Distance from a double value in meters.
Create a property “FtInFraction” to get the current distance as a string, or set the distance from a string, the string format you must use is specified below.
Write private methods as necessary to do the work required. Only the properties and constructor may be public.
Be sure to use proper rounding rules when converting floating point values to integers.
Write a short program in “main”. Inside main:
Create an instance of the object Distance defined by your class.
Distance Demo = new Distance(); Demo.Feet = 1.1; string FeetInchesFraction = Demo.FtInFraction; // should be: “1’ 1 13/64”” Demo.FtInFraction = “3’ 3 3/8””; Double Meters = Demo.Meters; // will be 1.00125 meters due to rounding
Do exhaustive testing with a screen shot of the console output. Exhaustive testing exercises the class through several thousand possibilities to verify the FtInFraction generates and interprets the string value in all cases. This is easily done with a loop.
Here is the code I've written so far for the class:
namespace Measurement_Converter
{
    class Distance
    {
        public double Meters
        {
            get
            {
                return Meters;
            }
            set
            {
                Meters = 0;
            }
        }

        // Feet 
        public double Feet
        {
            get
            {
                return Meters / .30480;
            }
            set
            {
                Meters = value * 3.34375;
            }
        }

        public string FeetString
        {
            get
            {
                StringBuilder SB = new StringBuilder();
                return SB.ToString();
            }
            set
            {
                string raw = value;
            }
        }

        // Inches
        private int SixtyFourths;

        public double Inches
        {
            get
            {
                return SixtyFourths;
            }
            set
            {
                SixtyFourths = 0;
                if (value % 2 == 0)
                    return;
                SixtyFourths = (int)(value / 2);
            }
        }

        public double FtInFraction
        {
            get
            {
                return FtInFraction;
            }
            set
            {

            }
        }
    }
}

And here is the code I've written for the main:
namespace Measurement_Converter
{
    class Program
    {
        static void Main(string[] args)
        {
            Distance T = new Distance();

            T.Meters = 12;

            string Test = T.FeetString;
        }
    }
}

My problem at the moment is that I am getting an stackoverflowexception at the set part of my meters class. My problems that are sure to follow are due to my lack of experience. I am hoping someone can help me understand the stack overflow error and possibly help me get an idea of what I might need to do with the rest of the program, or at least a similar example that i can use to try to make sense of this foreign language. Also, I get the gist of the assignment but if someone could try to explain the testing part in layman's terms. I don't want someone to do my work for me but this assignment is very confusing to me and it it is causing me a lot of frustration. 

A:

Your Metres property has the same name as the backing field (variable), and is being recursively called. You may have been confused by automatic properties versus declaring the 'backing' field yourself.
You can implement like this:
class Distance 
{
    private double _meters;

    public double Meters
    {
        get
        {
            return _meters;
        }
        set
        {
            _metres = value;
        }
    }

    .....

Or like this:
class Distance 
{
      public double Metres{ get; set; }

      ....

Ref: Auto-Implemented Properties

