示例#1
0
        public static void aggregate()
        {
            List <int> numbers = new List <int> {
                1, 2, 3, 4, 5, 6
            };

            Console.WriteLine(numbers.Min());
            Console.WriteLine(numbers.Max());
            Console.WriteLine(numbers.Sum());
            Console.WriteLine(numbers.Count());
            Console.WriteLine(numbers.Average());
            Console.WriteLine(numbers.Aggregate((a, b) => a + b));
            employeelist    list = new employeelist();
            List <employee> emps = new List <employee>
            {
                new employee {
                    Id = 10, Name = "keerthana", Gender = "Female"
                },
                new employee {
                    Id = 30, Name = "sravani", Gender = "Female"
                },
                new employee {
                    Id = 20, Name = "Sanjay", Gender = "Male"
                }
            };
            // employee emp = new employee;
            var result = emps.Where(emp => emp.Gender == "Female").Select(emp => new { Name = emp.Name, Gender = emp.Gender });

            foreach (var num in result)
            {
                Console.WriteLine(num.Name + " " + num.Gender);
            }
        }
示例#2
0
        public static void grouping()
        {
            employeelist list = new employeelist();

            var newset = list.emps.GroupBy(emp => emp.Gender);

            foreach (var group in newset)
            {
                Console.WriteLine(group.Key + " " + group.Count());
            }
        }
示例#3
0
        public static void conversion()
        {
            employeelist list = new employeelist();

            var newset = list.emps.ToDictionary(emp => emp.Id);
        }