public static IpCam getInstance(string ipAdress) { IpCam cam = null; if (ipAdress == null || (!camera.ContainsKey(ipAdress) && camera.Count < 3)) { cam = new IpCam(ipAdress); camera.Add(ipAdress, cam); } else { throw new ArgumentException(string.Format("{0} Eror!", ipAdress)); } return(cam); }
static void Main(string[] args) { try { IpCam cam1 = IpCam.getInstance("192.168.0.1"); WriteLine(cam1.IP); WriteLine(); IpCam cam2 = IpCam.getInstance("192.168.1.2"); WriteLine(cam2.IP); WriteLine(); IpCam cam3 = IpCam.getInstance("192.168.1.3"); WriteLine(cam3.IP); WriteLine(); ReadKey(); } catch (ArgumentException ex) { WriteLine(ex.Message); } }