M
Mash
I have the following dilemna. How do I return an instance of a struct
from a method.
For example:
private struct Me
{
private string name;
public string Name
{
get{return name;}
set{name=value;}
}
}
public Me GetMe()
{
Me mash = new Me();
mash.Name="Mash";
return mash;
}
Doing this gets a CS0050 error..accessibilty!!
If I do the following:
public object GetMe()
{
Me mash = new Me();
mash.Name="Mash";
return (object)mash;
}
All is well...I then have to "un-Box" mash when I want to use it.
Questions are:
Does this give me any benefit over using a class?
Does the struct now reside on the HEAP or STACK.
If I change the struct to public it all works. Is this good practice?
Does the struct instance, mash, retain it's private accessibility when
I have boxed/un-boxed?
What is the accepted practice for passing structs between classes?
Thanks for any help.
Mash
from a method.
For example:
private struct Me
{
private string name;
public string Name
{
get{return name;}
set{name=value;}
}
}
public Me GetMe()
{
Me mash = new Me();
mash.Name="Mash";
return mash;
}
Doing this gets a CS0050 error..accessibilty!!
If I do the following:
public object GetMe()
{
Me mash = new Me();
mash.Name="Mash";
return (object)mash;
}
All is well...I then have to "un-Box" mash when I want to use it.
Questions are:
Does this give me any benefit over using a class?
Does the struct now reside on the HEAP or STACK.
If I change the struct to public it all works. Is this good practice?
Does the struct instance, mash, retain it's private accessibility when
I have boxed/un-boxed?
What is the accepted practice for passing structs between classes?
Thanks for any help.
Mash