[Mono-list] Constructors in C#

Robert Shade rshade@dvsconsulting.com
Fri, 19 Nov 2004 17:38:34 -0500


How about a static method that returns a new instance?

   public class MyClass
   {
       private string login;
       private int uid;
       private string home;

       public MyClass (string login, int uid, string home)
       {
           // affect things
       }

       public static MyClass FromLine(string line)
       {
           System.text.RegularExpression.Regex.Split(line, ":");
           /* make some checks
            * (second field is an int, and so on ...) */
           // call next constructor

	 return new MyClass(login, uid, home);
       }
   }

rob