Hi,
with this code, i get nothing. It's because the array in class View is empty. Yet, the method Show() starts after the array is filled in Main. How can i show those data in method Show()?
Thanks
V.
using System;
class Stman
{
public string[] Name = new string[3];
static void Main(string[] args)
{
Stman myObj = new Stman();
View dat = new View();
myObj.Name[0] = "Macron";
myObj.Name[1] = "Rutte";
myObj.Name[2] = "Sunak";
dat.Show();
}
}
class View
{
public void Show()
{
Stman myObj = new Stman();
for (int i = 0; i < myObj.Name.Length; i++)
Console.WriteLine(myObj.Name[i]);
}
}
Aravind GovindarajPosted Dec 9, 2022, 6:52 PM
please follow this
Valerie MeunierPosted Dec 13, 2022, 3:56 PM
Thanks.
Pankajkumar PatelPosted Dec 12, 2022, 6:47 AM
Hi Valerie Meunier,
To show data in another class you can do it by passign class object to that method for this implementation as like following:
Hope this will help you!
Valerie MeunierPosted Dec 10, 2022, 9:13 AM
Thanks for replying. There are some errors in your code. Did you test it?
It must be dat.Name[0] = "Macron";
Also the last line must be Console.WriteLine(Name[i]
But what i want to know is why mijn code doesn't work? The only explanation i found is that myObj.Name[i] in method Show not the same is as in Main.