clemtuf
Member
- Joined
- Jan 7, 2023
- Messages
- 5
- Programming Experience
- 3-5
Hi,
This code gives two errors (bold lines). For the first error, i could add this: Stm myObj2 = new Stm()]; or change the line into myObj[0][0].show(); but i don't find it very elegant and it doesn't work for the second error (in the method show).
Thanks
R.
This code gives two errors (bold lines). For the first error, i could add this: Stm myObj2 = new Stm()]; or change the line into myObj[0][0].show(); but i don't find it very elegant and it doesn't work for the second error (in the method show).
Thanks
R.
C#:
using System;
class Stm
{
string name;
static void Main(string[] args)
{
Stm[] myObj = new Stm[3];
for (int i = 0; i < myObj.Length; i++)
myObj = new Stm();
myObj[0].name = "Macron";
myObj[1].name = "Biden";
myObj[2].name = "Sunak";
myObj[0].show();
}
void show()
{
for (int i = 0; i < myObj.Length; i++)
Console.WriteLine(name);
}
}
Last edited by a moderator: