示例#1
0
        static void Main(string[] args)
        {
            //int[] array = new int[] { 1, 2, 3, 4 };
            //int[][] jagged = { new int[] { 1, 2, 3 }, new int[] { 1 }, new int[] { 5, 5, 5, 5, 5 } };
            //int[,] arr =new int[,] { { 1, 2, 3 }, { 4, 5, 6 } };
            //int l = arr.GetLength(1);
            //Student student = new Student("Ivan Petrov", 25);
            //Student student1 = new Student();
            //Student student2 = new Student(student);
           
            //Console.WriteLine(student.ToString());
            //Console.WriteLine(student1);
            //Console.WriteLine(student2);

            //Random rnd = new Random();
            

            //int[] arr2 = new int[] { 1, 2, 3, 4 };
            //int[] arr3 = new int[arr2.Length];
            //Array.Copy(arr2, arr3, arr2.Length);
            //arr3[0] = 777;
            //Console.WriteLine(arr2[0]);
            //Console.WriteLine(arr3[0]);
            Student student5 = new Student("Ivan Petrov",24,1600);
            Console.WriteLine(student5.AgeInFee());
            Console.WriteLine("The first letter of the name is {0}", student5.Firstchar());
            Console.WriteLine("Fee: {0}", student5.Fee);
            StudentExtension.IncreaseFee(student5, 15);
            Console.WriteLine("Fee increased with 15%: {0}", student5.Fee);
            Student one = new StudentExt("Georgi", 24, 1600,"Male");
            one.Talk();

        }
示例#2
0
        public void Linq2_3Test()
        {
            Student ivan   = new Student("Ivan", "222", Gender.Male);
            Student ana    = new Student("Ana", "00036", Gender.Female);
            Student ante   = new Student("Ante", "011111", Gender.Male);
            Student prokop = new Student("Prokop", "3333", Gender.Male);
            Student zakop  = new Student("Zakop", "3333334444", Gender.Male);

            Student[] students1 = new Student[]
            {
                ivan,

                ana
            };

            Student[] students2 = new Student[]
            {
                ivan,

                ante
            };

            Student[] students3 = new Student[]
            {
                ana,

                prokop
            };

            Student[] students4 = new Student[]
            {
                zakop,
                prokop
            };

            University fer  = new University("FER", students3);
            University ffzg = new University("FFZG", students1);
            University tvz  = new University("TVZ", students2);
            University fkit = new University("FKIT", students4);

            University[] universities = new University[]
            {
                ffzg,

                tvz,

                fer,

                fkit
            };

            Student[] filtered = HomeworkLinqQueries.Linq2_3(universities);
            Student[] expected = new Student[]
            {
                ivan,
                ana,
                ante,
                zakop,
                prokop
            };

            CollectionAssert.AreEquivalent(expected, filtered);
        }
示例#3
0
文件: Student.cs 项目: shubidu/csharp
        public Student(Student s)
            : this(s.Name, s.Age, s.Fee)
        {

        } 
示例#4
0
        static void Main()
        {
            string buffer = new string('-', 40);

            Console.WriteLine($"{buffer}Problem1.StringBuilder.SubString Extencion{buffer}\r\n");
            TestsMethods.StringBuilder();
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem2.IEnumerable Extensions{buffer}\r\n");
            TestsMethods.IEnumerableInt(new List <int>()
            {
                2, 1, 5, 3, 4
            });
            TestsMethods.IenumerableDouble(new List <double>()
            {
                2.1, 1.5, 5.4, 3.2, 4.8
            });
            Console.WriteLine();

            var students = new Student[]
            {
                new Student("Pavel", "Angelov", 29, "02/9252525", "*****@*****.**", new List <double>()
                {
                    4, 6, 6, 5, 6
                }, new Group(2, "Mathematics")),
                new Student("Anton", "Dimitrov", 19, "032/9443322", "*****@*****.**", new List <double>()
                {
                    4, 6
                }, new Group(3, "Art")),
                new Student("Daniel", "Georgiev", 32, "0719/927", "*****@*****.**", new List <double>()
                {
                    4, 4, 6
                }, new Group(1, "Biology")),
                new Student("Krasimir", "Angelov", 26, "02/9254422", "*****@*****.**", new List <double>()
                {
                    4, 2, 4, 2, 6
                }, new Group(2, "Mathematics")),
                new Student("Aleksander", "Ivanov", 33, "0883212121", "*****@*****.**", new List <double>()
                {
                    5, 6
                }, new Group(1, "Biology")),
                new Student("Kiril", "Petkov", 22, "0897123123", "*****@*****.**", new List <double>()
                {
                    4, 3, 4, 4, 6
                }, new Group(3, "Art")),
                new Student("Rangel", "Dimitrov", 40, "0888223344", "*****@*****.**", new List <double>()
                {
                    4, 3, 4, 4, 6
                }, new Group(2, "Mathematics")),
                new Student("Ivan", "Petrov", 36, "0878765432", "*****@*****.**", new List <double>()
                {
                    4, 3, 4, 4, 6
                }, new Group(3, "Art")),
                new Student("Gospodin", "Kostadinov", 31, "0899112233", "*****@*****.**", new List <double>()
                {
                    4, 3, 4, 4, 6
                }, new Group(2, "Mathematics"))
            };

            Console.WriteLine($"{buffer}Problem 3. First before last{buffer}\r\n");
            var selectedByName = TestStudentsWithLINQ.FirstNameBeforeLastName(students);

            TestsMethods.IntroduceStudents(selectedByName);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 4. Age range{buffer}\r\n");
            var selectedByAge = TestStudentsWithLINQ.SelectByAge(students, 18, 24);

            TestsMethods.IntroduceStudents(selectedByAge);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 5. Order students{buffer}\r\n");
            var sortedByName = TestStudentsWithLambda.LambdaSortedByName(students);

            TestsMethods.IntroduceStudents(sortedByName);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 6. Divisible by 7 and 3{buffer}\r\n");
            var numbers   = new int[] { 2, 3, 4, 54, 21, 63, 35, 70, 42, 25 };
            var divisible = TestsMethods.FindDivisibleBy7And3(numbers);

            Console.WriteLine(TestsMethods.CollectionToString(divisible) + "\r\n");

            Console.WriteLine($"{buffer}Problem 9. Student groups{buffer}\r\n");
            var selectedByGroup = TestStudentsWithLINQ.GetStudentsByGroup(students, 2);

            TestsMethods.IntroduceStudents(selectedByGroup);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 11. Extract students by email{buffer}\r\n");
            var selectedByEmail = TestStudentsWithLINQ.GetStudentsByEmail(students, "abv.bg");

            TestsMethods.IntroduceStudents(selectedByEmail);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 12. Extract students by phone{buffer}\r\n");
            var selectedByPhone = TestStudentsWithLINQ.GetStudensByZipCode(students, "02/");

            TestsMethods.IntroduceStudents(selectedByPhone);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 13. Extract students by marks{buffer}\r\n");
            var selectByMarks =
                from student in students
                where student.Marks.Contains(6)
                select new { FullName = student.FullName, Marks = student.Marks };

            foreach (var st in selectByMarks)
            {
                Console.Write($"Name: {st.FullName}, ");
                Console.Write($"Marks: {TestsMethods.CollectionToString(st.Marks)}");
                Console.WriteLine();
            }
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 14. Extract students by marks{buffer}\r\n");
            var studentsWithTwoMarks = TestStudentsWithLambda.ExtractByNumberOfMarks(students, 2);

            TestsMethods.IntroduceStudents(studentsWithTwoMarks);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 16.* Groups{buffer}\r\n");
            var studentsByDeptName = TestStudentsWithLambda.ExtractStudentsByDepartName(students, "Mathematics");

            Console.WriteLine(studentsByDeptName);

            Console.WriteLine($"{buffer}Problem 17. Longest string{buffer}\r\n");
            var text = "By using delegates, develop an universal static method.";

            Console.WriteLine(TestsMethods.LongestString(text + "\r\n"));

            Console.WriteLine($"{buffer}Problem 18. Grouped by GroupNumber{buffer}\r\n");
            TestStudentsWithLINQ.GroupByGroupNumber(students);
            Console.WriteLine();

            Console.WriteLine($"{buffer}Problem 19. Grouped by GroupName extensions{buffer}\r\n");
            TestStudentsWithLINQ.GroupByGroupName(students);
            Console.WriteLine();
        }