コード例 #1
0
        public static GraduateStudet GenerateElement(int i)
        {
            GraduateStudet gr = new GraduateStudet();

            gr.PersonProperty = new Person(gr.Name, gr.LastName + i, gr.Date);
            return(gr);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: irynayudina/laboratorna4
            static void AddRandEllements(GraduateStudentCollection gst)
            {
                int amount = 10;

                GraduateStudet[] gradArr = new GraduateStudet[amount];
                for (int i = 0; i < amount; i++)
                {
                    gradArr[i] = new GraduateStudet();
                }
                Random rand           = new Random();
                int    lastNameInt    = 0;
                int    learnigYearInt = 0;
                int    y = 0;

                for (int i = 0; i < amount; i++)
                {
                    lastNameInt             = rand.Next(1, 400);
                    learnigYearInt          = rand.Next(1, 4);
                    gradArr[i].LearningYear = learnigYearInt;
                    y = rand.Next(DateTime.Today.Year - learnigYearInt - 30, DateTime.Today.Year - learnigYearInt - 18);
                    gradArr[i].ChangeBirthday = y;
                    gradArr[i].PersonProperty = new Person(gradArr[i].Name, gradArr[i].LastName + lastNameInt, gradArr[i].Date);
                }
                gst.AddGraduateStudents(gradArr);
            }
コード例 #3
0
ファイル: Program.cs プロジェクト: irynayudina/laboratorna4
        static void Main()//string[] args
        {
            int size = Positive();
            GraduateStudentCollection gst = new GraduateStudentCollection();

            gst.AddDefaults();
            //##########################//Add elements to GraduateStudetCollection//############################
            AddRandEllements(gst);
            //################################################################################
            Console.WriteLine(gst.ToString());
            Console.WriteLine("Elements of GraduateStudentCollection sorted by name:########################################");
            gst.SortByLastName();
            Console.WriteLine(gst.ToString());
            Console.WriteLine("Elements of GraduateStudentCollection sorted by birthday:####################################");
            gst.SortByBirthday();
            Console.WriteLine(gst.ToString());
            Console.WriteLine("Elements of GraduateStudentCollection sorted by learning year:###############################");
            gst.SortByLearningYear();
            Console.WriteLine(gst.ToString());
            TestCollections testColl    = new TestCollections(size);
            GraduateStudet  first       = TestCollections.GenerateElement(0);
            GraduateStudet  middle      = TestCollections.GenerateElement(size / 2);
            GraduateStudet  last        = TestCollections.GenerateElement(size - 1);
            GraduateStudet  notexisting = TestCollections.GenerateElement(size + 1);

            Console.WriteLine("Searching time for the first element:################################################");
            testColl.CalculateTime(first);
            Console.WriteLine("Searching time for the middle element:###############################################");
            testColl.CalculateTime(middle);
            Console.WriteLine("Searching time for the last element:#################################################");
            testColl.CalculateTime(last);
            Console.WriteLine("Searching time for not existing element:#############################################");
            testColl.CalculateTime(notexisting);
コード例 #4
0
        public void CalculateTime(GraduateStudet g)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();
            if (PersonList.Contains(g.PersonProperty))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts1d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element in list of persons: {ts1d}");
            stopWatch.Start();
            if (stringList.Contains(g.PersonProperty.ToString()))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts2d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element in list of strings: {ts2d}");
            stopWatch.Start();
            if (typedKVDictionary.ContainsKey(g.PersonProperty))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts3d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element by key in Dictionary<Person, GraduateStudet>: {ts3d}");
            stopWatch.Start();
            if (typedKVDictionary.ContainsValue(g))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts4d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element by value in Dictionary<Person, GraduateStudet>: {ts4d}");
            stopWatch.Start();
            if (typedStringVDictionary.ContainsKey(g.PersonProperty.ToString()))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts5d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element by key in Dictionary<string, GraduateStudet>: {ts5d}");
            stopWatch.Start();
            if (typedStringVDictionary.ContainsValue(g))
            {
                Console.WriteLine("contains");
            }
            stopWatch.Stop();
            TimeSpan ts6d = stopWatch.Elapsed;

            Console.WriteLine($"Time to find the element by value in Dictionary<string, GraduateStudet>: {ts6d}");
        }
コード例 #5
0
 public TestCollections(int elem)
 {
     for (int i = 0; i < elem; i++)
     {
         GraduateStudet g = GenerateElement(i);
         PersonList.Add(g.PersonProperty);
         stringList.Add(g.PersonProperty.ToString());
         typedKVDictionary.Add(g.PersonProperty, g);
         typedStringVDictionary.Add(g.PersonProperty.ToString(), g);
     }
 }
コード例 #6
0
 void InsertAt(int j, GraduateStudet gs)
 {
     if (ListOfStudents[j] != null)
     {
         ListOfStudents.Insert(j - 1, gs);
         //GraduateStudentAdded.Invoke
     }
     else
     {
         ListOfStudents.Add(gs);
     }
 }
コード例 #7
0
        public void AddDefaults()
        {
            /*c допомогою якого можна додати деяке число елементів
             * типу GraduateStudent для ініціалізації колекції за замовчуванням; */
            int sizedef = 7;

            GraduateStudet[] p = new GraduateStudet[sizedef];
            for (int i = 0; i < sizedef; i++)
            {
                GraduateStudet grd = new GraduateStudet();
                grd.LastName = grd.LastName + i;
                p[i]         = grd;
            }
            ListOfStudents.AddRange(p);
        }
コード例 #8
0
        public override object DeepCopy()
        {
            GraduateStudet g = (GraduateStudet)this.MemberwiseClone();

            g.PersonProperty    = (Person)this.PersonProperty.DeepCopy();
            g.EmployeePosition  = new string(EmployeePosition); //String.Copy(EmployeePosition);
            g.Supervisor        = (Person)this.Supervisor.DeepCopy();
            g.Speciality        = new string(Speciality);       //String.Copy(Speciality);
            g.ArticlesPublished = new List <Article>();
            for (int i = 0; i < ArticlesPublished.Count; i++)
            {
                g.ArticlesPublished.Add((Article)this.ArticlesPublished[i].DeepCopy());
            }
            g.NotesMade = new List <Notes>();
            foreach (Notes n in this.NotesMade)
            {
                g.NotesMade.Add((Notes)n.DeepCopy());
            }
            return(g);
        }