I have a simple class that creates unique ID numbers:

public static class ID
    {
        private static int iD = 0;

        public static int GetNextID()
        {
            return iD++;
        }
    }

If I want each instance of an abstract class to automatically get a new non changeable ID when instantiated, how do I go about that?

The following won't work:

public abstract class MyClass
    {
        protected const int ID = ID.GetNextID();
    }

Try this:

protected readonly int ID = ID.GetNextID();

Perfect, thank you :)

Just dont forget to mark the thread as salved if you are satisfied with the answer :)
bye

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.