I'm trying to get to the just of the Out parameter. I have seen many examples, but they all have a method where there is no new class that is used..
I get 2 errors when calling this test code:
The out parameter 'w' must be assigned to before control leaves the current method.
Use of unassigned out parameter 'w'.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Widget newWidget;
Widget.Create(out newWidget);
}
}
class Widget
{
private String name;
public String Name { get { return name; } set { name = value; } }
public static void Create(out Widget w)
{
w.name = "1";
}
}
This works , but what does it help?
public static void Set(out Widget w)
{
Widget x = new Widget();
x.name = "1";
w = x;
}