Aug 12 2016

How can you create a c# class that creates instances of itself using a static method but still has access to the instance methods and properties?

I am trying to create a class that can create itself using a static method but where you can still access the instance member after it creates itself. Why am I finding this so hard to do?

public class Widget
{
  public static Widget Init()
  {
    return new Widget();
  }

  public string WidgetUPC {get; set;}
}

...when I create an instance like this...

var w = Widget.Init();

I cannot set the property like this...

w.WidgetUPC = 'someUPC';

The instance Why not?

What changes can I make to get this to work?