#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;

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: