public class ProductCoder { static Hashtable coders=new Hashtable(); private int _number; private string _prefix=""; private ProductCoder(){} public static ProductCoder Instance(string prefix){ ProductCoder p=null; if(coders.Contains(prefix)){ p=(ProductCoder)coders[prefix]; } else lock(coders){ p=new ProductCoder(); p._prefix=prefix; coders.Add(prefix,p); } return p; } public string Prefix{ get{return _prefix;} } public string GetNewCode(){ return(string.Format("{0}{1:000}",_prefix,++_number)); } public string GetLastCode(){ return (string.Format("{0}{1:000}",_prefix,++_number)); } }