0

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.

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Asotop
0

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.

Edited by thines01: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.