I’m trying to pass a struct from one object to another. I have the following code:
private void mainMenuStripNewProject_Click(object sender, EventArgs e)
{
frmNewProject frmNewProject = new frmNewProject(this);
if (frmNewProject.ShowDialog() == DialogResult.OK)
{
StructProjectSettings tempProjectSettings = frmNewProject.getSettings();
newProjectEvent(tempProjectSettings); //Fetchs settings from the new project form
}
}
However, I get the following error:
Error 14 Cannot implicitly convert type ‘NathanUpload.frmNewProject.StructProjectSettings’ to ‘NathanUpload.Main.StructProjectSettings’ o:\daten\visual studio 2010\Projects\NathanUpload\NathanUpload\Main.cs 43
The structs in each class are declared public class variables and are identical.
Thanks for the help in advance!
Have you defined the actual struct inside each of the classes?
Even if you use the same name on them, the compiler won’t treat them as the same type.
You have to define the struct in one place, and make object of it from both classes that needs to use it.
An example
This is not allowed, and this is actually what you are trying to do. I suggest moving the struct out of the class and put it somewhere both classes can access it.
Define it like this instead