public static void Main(string[] args) { ResearchTeam obj = new ResearchTeam(); Console.WriteLine(obj.ToShortString()); Console.WriteLine(obj[TimeFrame.Year]); Console.WriteLine(obj[TimeFrame.TwoYears]); Console.WriteLine(obj[TimeFrame.Long]); obj.DurationOfResearch = TimeFrame.TwoYears; obj.OrganizationName = "Bionic"; obj.RegistrationNumber = 0; obj.ResearchTopic = "Snakes"; Console.WriteLine(obj); Paper[] papers = new Paper[2]; for (int i = 0; i < papers.Length; i++) { papers[i] = new Paper(); } papers[0].Author = new Person("Richard", "Markov", new DateTime(1897, 12, 11)); papers[0].PublicationDate = new DateTime(2012, 12, 12); papers[0].PublicationName = "Cobra"; papers[1].Author = new Person("Nelly", "Stenly", new DateTime(1991, 4, 25)); papers[1].PublicationDate = new DateTime(2015, 8, 22); papers[1].PublicationName = "Black Mamba"; obj.AddPapers(papers); Console.WriteLine(obj); Console.WriteLine(obj.LastPublication); }
static void Main(string[] args) { ResearchTeam RT = new ResearchTeam(); Console.WriteLine(RT.ToShortString()); Console.WriteLine(RT[TimeFrame.Year]); Console.WriteLine(RT[TimeFrame.TwoYears]); Console.WriteLine(RT[TimeFrame.Long]); RT.TopicOfResearch = "Topic"; RT.NameOfOrganisation = "Some Name"; RT.RegistrationNumber = 12345; RT.DurationOfResearch = TimeFrame.TwoYears; RT.ListOfPublication = new Paper[1] { new Paper { Name = "some paper", Author = new Person(fName: "Roman", sName: "Chubak", bDay: DateTime.Today), DateOfPublication = DateTime.Today } }; Console.WriteLine(RT); RT.AddPapers( new Paper { Name = "paper", Author = new Person(fName: "Oleh", sName: "Bodnar", bDay: DateTime.Today), DateOfPublication = DateTime.Today }); Console.WriteLine(RT); Console.WriteLine(RT.LastPublication); Console.WriteLine("\n\n\n"); Console.WriteLine("enter the number of rows and columns separated by spaces: "); string[] nm = Console.ReadLine().Split(' '); int nRows = Convert.ToInt32(nm[0]); int nColums = Convert.ToInt32(nm[1]); ResearchTeam[] arr = new ResearchTeam[nRows * nColums]; for (int i = 0; i < arr.Length; i++) { arr[i] = new ResearchTeam(); } ResearchTeam[,] arr2 = new ResearchTeam[nRows, nColums]; for (int i = 0; i < nRows; i++) { for (int j = 0; j < nColums; j++) { arr2[i, j] = new ResearchTeam(); } } ResearchTeam[][] arr3 = new ResearchTeam[WhatNumberOfRows(nRows * nColums)][]; for (int i = 0; i < arr3.Length; i++) { arr3[i] = new ResearchTeam[i + 1]; for (int j = 0; j < arr3[i].Length; j++) { arr3[i][j] = new ResearchTeam(); } } int start = Environment.TickCount; foreach (var element in arr) { element.NameOfOrganisation = "afsa"; } int end = Environment.TickCount; Console.WriteLine("one-dimensional array : " + (end - start) + "msec"); start = Environment.TickCount; foreach (var element in arr2) { element.NameOfOrganisation = "afsa"; } end = Environment.TickCount; Console.WriteLine("two-dimensional array : " + (end - start) + "msec"); start = Environment.TickCount; foreach (var firstDemention in arr3) { foreach (var secondDemention in firstDemention) { secondDemention.NameOfOrganisation = "afsa"; } } end = Environment.TickCount; Console.WriteLine("stepped array array : " + (end - start) + "msec"); Console.ReadKey(); }
static void Main(string[] args) { int NumberOfElements = 0; Console.WriteLine("Please, enter the number of elements in one - dimensional array"); NumberOfElements = Convert.ToInt32(Console.ReadLine()); Paper[] ODArray = new Paper[NumberOfElements]; for (int i = 0; i < NumberOfElements; i++) { ODArray[i] = new Paper(); } Console.WriteLine("Please, enter rows and columns of two - dimensional array, using ',': "); string[] RowsAndColumnsTDArr = Console.ReadLine().Split(','); int NumberOfRowsInTDArray = int.Parse(RowsAndColumnsTDArr[0]); int NumberOfColumnsInTDArray = int.Parse(RowsAndColumnsTDArr[1]); Paper[,] TDArray = new Paper[NumberOfRowsInTDArray, NumberOfColumnsInTDArray]; for (int i = 0; i < NumberOfRowsInTDArray; i++) { for (int j = 0; j < NumberOfColumnsInTDArray; j++) { TDArray[i, j] = new Paper(); } } Console.WriteLine("Please, enter rows and columns of ragged array, using ',': "); string[] RowsAndColumnsRaggedArr = Console.ReadLine().Split(','); int NumberOfColumnsInRaggedArray = int.Parse(RowsAndColumnsRaggedArr[0]); int NumberOfRowsInRaggedArray = int.Parse(RowsAndColumnsRaggedArr[1]); Paper[][] RaggedArray = new Paper[NumberOfRowsInRaggedArray][]; for (int i = 0; i < NumberOfRowsInRaggedArray; i++) { RaggedArray[i] = new Paper[NumberOfColumnsInRaggedArray]; } for (int i = 0; i < NumberOfRowsInRaggedArray; i++) { for (int j = 0; j < NumberOfColumnsInRaggedArray; j++) { RaggedArray[i][j] = new Paper(); } } int start = Environment.TickCount; for (int i = 0; i < NumberOfElements; i++) { ODArray[i].Name = "qwe"; } int end = Environment.TickCount - start; Console.WriteLine("First result is: " + end); start = Environment.TickCount; for (int i = 0; i < NumberOfRowsInTDArray; i++) { for (int j = 0; j < NumberOfColumnsInTDArray; j++) { TDArray[i, j].Name = "qwe"; } } end = Environment.TickCount - start; Console.WriteLine("Second result is: " + end); start = Environment.TickCount; for (int i = 0; i < NumberOfRowsInRaggedArray; i++) { for (int j = 0; j < NumberOfColumnsInRaggedArray; j++) { RaggedArray[i][j].Name = "qwe"; } } end = Environment.TickCount - start; Console.WriteLine("Third result is: " + end); Console.WriteLine("\n-----------------------------------------------------\n"); ResearchTeam DyatlovTeam = new ResearchTeam("Pereval", "Dyatlov Team", 6845312, TimeFrame.Year); Console.WriteLine(DyatlovTeam.ToShortString()); Console.WriteLine(); Console.WriteLine(DyatlovTeam[TimeFrame.Year]); Console.WriteLine(DyatlovTeam[TimeFrame.TwoYears]); DyatlovTeam.ResearchPublications = new Paper[] { new Paper() }; Person Dyatlov = new Person("Igor", "Dyatlov", new DateTime(1936, 01, 13)); Paper p1 = new Paper("Taina", Dyatlov, new DateTime(1959, 02, 02)); Paper p2 = new Paper("Taina2", Dyatlov, new DateTime(1960, 02, 03)); DyatlovTeam.AddPapers(p1, p2); Console.WriteLine(DyatlovTeam.ToShortString()); Console.ReadKey(); }
static void Main(string[] args) { ResearchTeam team = new ResearchTeam(); Console.WriteLine(team.ToShortString()); Console.WriteLine($"Индексатор для Year = : Year = {team[TimeFrame.Year]} TwoYears = {team[TimeFrame.TwoYears]} Long = {team[TimeFrame.Long]}\n"); team.ResearchName = "Поиск Немо"; team.ResearchDuration = TimeFrame.TwoYears; team.LicenceNumber = 18999; team.CompanyName = "ООО \"Рыболов\""; team.ArticleArr = new Paper[] { new Paper(), new Paper("Первая попытка", new Person(), new DateTime(2002, 8, 13)), new Paper("Вторая попытка", new Person("Фёдр", "Макгрегор", new DateTime(2009, 2, 9)), new DateTime(2010, 10, 12)) }; Console.WriteLine(team.ToString() + "\n"); team.AddPapers(new Paper("Новое исследование", new Person("Иван", "Иванов", new DateTime(1998, 10, 7)), new DateTime(2021, 9, 10))); Console.WriteLine(team.ToString() + "\n"); Console.WriteLine("Последнее исследование: \n" + team.LastArticle.ToString()); //Сравнение скорости работы для одномерного, прямоугольного и ступенчатого массива string[] strArr = null; int strNum = 0, colNum = 0; while (true) { Console.WriteLine("Введите ncol, nrow, через запятую"); string line = Console.ReadLine(); strArr = line.Split(','); try { strNum = Int32.Parse(strArr[0]); colNum = Int32.Parse(strArr[1]); break; } catch (FormatException) { Console.WriteLine("Вы допустили ошибку при вводе!"); } catch (ArgumentNullException) { Console.WriteLine("Вы допустили ошибку при вводе!"); } } int resSize = strNum * colNum; Paper[] paperLinearArr = new Paper[resSize]; for (int i = 0; i < resSize; i++) { paperLinearArr[i] = new Paper(); } Random random = new Random(); Paper[][] paperStairsArr = new Paper[strNum][]; for (int i = 0; i < strNum - 1; i++) { int t_size = random.Next(1, colNum); paperStairsArr[i] = new Paper[t_size]; resSize -= t_size; } paperStairsArr[strNum - 1] = new Paper[resSize]; for (int i = 0; i < paperStairsArr.Length; i++) { for (int j = 0; j < paperStairsArr[i].Length; j++) { paperStairsArr[i][j] = new Paper(); } } Paper[,] paperRectangleArr = new Paper[strNum, colNum]; for (int i = 0; i < strNum; i++) { for (int j = 0; j < colNum; j++) { paperRectangleArr[i, j] = new Paper(); } } Stopwatch sw = new Stopwatch(); sw.Start(); foreach (Paper[] arr in paperStairsArr) { foreach (Paper item in arr) { item.ArticleName = "NewName"; } } sw.Stop(); Console.WriteLine("Результат для зубчатого массива: " + sw.ElapsedMilliseconds.ToString()); sw.Restart(); foreach (Paper item in paperRectangleArr) { item.ArticleName = "NewName"; } sw.Stop(); Console.WriteLine("Результат для прямоугольного массива: " + sw.ElapsedMilliseconds.ToString()); sw.Restart(); foreach (Paper item in paperLinearArr) { item.ArticleName = "NewName"; } sw.Stop(); Console.WriteLine("Результат для линейного массива: " + sw.ElapsedMilliseconds.ToString()); }