#719 – Location of Declarations within A Class Doesn’t Matter

Within the code for a class, you can declare members either before or after they are used.

In the example below, the Name property is declared earlier in the class than it is used.  But the secretName field is declared after it is used.

    public class Dog
    {
        public string Name { get; set; }

        public Dog(string name)
        {
            Name = name;
            secretName = "His Great Terribleness Mr. Bites-a-Lot";
        }

        public void RevealNames()
        {
            Console.WriteLine(string.Format("{0} is really {1}", Name, secretName));
        }

        private string secretName;
    }
Advertisement