Hey!

I'm currently at the end of a task im working on, which consist of a class named CD, and in the main program i got a method which register a CD. And i want the created class to be named CD1, CD2 etc.

public static int cdNumber = 1;
 static void RegisterANewCD()
         {
            string name = "CD" + cdNumber;
            CD name  = new CD();
            cdNumber++;
                
         }

This clearly doesnt work since i cant name class object like that. What should I do?

Asotop.

Are you saying you want to have multiple CD objects?

Use a list or an array (rather than a number)

List<CD> lstCD = new List<CD)();
...then reference it with a ForEach or by its position.

When you add a new CD, the count will auto increment.

Thanks, it worked out with an array :)