Exemple #1
0
        public static void MainTest1(string[] args)
        {
            SimpleLogger logger = new SimpleLogger();

            Console.WriteLine("Hello World!");

            logger.Info("==================================");

            List <Class1> listClass1 = new List <Class1>();

            for (int i = 0; i < 20; i++)
            {
                Class1 cls1 = new Class1();
                cls1.ID      = 120000 + i;
                cls1.NAME    = cls1.ID + "-NAME";
                cls1.JOB_NUM = cls1.ID + "-JOBNUM";

                listClass1.Add(cls1);
                logger.Info("1. ID = " + UniqueID.GetRefId(cls1));
            }

            logger.Info("-----------------------------------");

            foreach (Class1 n in listClass1)
            {
                logger.Info(n.ID + " " + n.JOB_NUM);
                logger.Info("2. ID = " + UniqueID.GetRefId(n));
            }

            logger.Info("************************************");

            foreach (Class1 n in listClass1)
            {
                n.JOB_NUM = n.GetRefId().ToString();
                logger.Info("2. ID = " + UniqueID.GetRefId(n));
                logger.Info("2. JN = " + n.JOB_NUM);
            }


            #if (false)
            DateTime datetime = DateTime.MinValue.AddDays(3);
            Console.WriteLine(datetime);  // 4/1/0001 12:00:00 AM

            // TODO: Implement Functionality Here
            List <Class1> listClass1 = new List <Class1>();
            for (int i = 0; i < 20; i++)
            {
                Class1 cls1 = new Class1();
                cls1.ID      = 120000 + i;
                cls1.NAME    = cls1.ID + "-NAME";
                cls1.JOB_NUM = cls1.ID + "-JOBNUM";

                listClass1.Add(cls1);
            }

            // this returns reference to object that matches
            IEnumerable <Class1> listcls = listClass1.Where(a => a.ID == 120003);
            if (listcls.Any())
            {
                Class1 ncls = listcls.FirstOrDefault();
                ncls.JOB_NUM = "Just Changed";
            }

            // Now print out listClass1 to see whether the record with ID of 120003 has its JOB_NUM changed..
            foreach (Class1 n in listClass1)
            {
                Console.WriteLine(n.ID + " " + n.JOB_NUM);
            }

            Console.WriteLine("Removing the element with JOB_NUM == 'Just Changed'");

            listcls = listClass1.Where(a => a.JOB_NUM == "Just Changed");
            if (listcls.Any())
            {
                Class1 ncls = listcls.FirstOrDefault();
                listClass1.Remove(ncls);
            }

            Console.WriteLine("Removed the element");

            // Now print out listClass1 again
            foreach (Class1 n in listClass1)
            {
                Console.WriteLine(n.ID + " " + n.JOB_NUM);
            }
            #endif
        }