0

Code return errors help me

Hi, the code below from where i wrote an indexer to last line return errors like: "," ecpexted, "[" expected, etc. I have no idea why it return errors. namespace SoloLearn { class Program { static void Main(string[] args) { MusicGenres genres = new MusicGenres(); int count = 0; while (count<5) { genres[count] = Console.ReadLine(); count++; } for (int i = 0; i < 5; i++) { Console.WriteLine("Following: " + genres[i]); } } } class MusicGenres { private string[] genres = new string[5]; //declare an indexer public string this(int index) { get{return genres[index];} set{genres[index] = value;} } } }

4th May 2021, 3:51 PM
Mateusz
Mateusz - avatar
2 ответов
+ 1
public string this(int index) "int index" should be in "[ ]" public string this[int index] { get { return genres[index]; } set { genres[index] = value; } } And it's all problem 😉
4th May 2021, 10:05 PM
TouchiHe
TouchiHe - avatar
0
Thank you :D , i didnt saw it lol
5th May 2021, 4:05 AM
Mateusz
Mateusz - avatar