Hey
I am a beginner to c#.
I was wondering what you do when you have an array of objects such as:
//assume dog is a class that does something
private Dog[] dogs;
int numberOfDogs = 2;
for (int i = 0; i < numberOfDogs; i++) {
Console.WriteLine("Please enter your name");
dogs[i] = dogs[i].GetName();// This is where I get the error Cannot implicitly convert type 'string' to type DogNames.Dog
}
Dog.cs:
public string GetName(){
Console.WriteLine("Please enter your name");
string name = Console.ReadLine();
return name;
}
I understand the bug. The type is Dog not string, but how do I get around this?? When it's a string to object I just use .toString or casting (string) but I can't exactly do toObject or toDog? An explanation would be great. I keep getting stuck on this with everything I try to program.