コード例 #1
0
        public static void BasicEntitySample()
        {
            var employees = new SampleData().GetEmployees();

            var empdata = employees.Where(e => e.Department == "Sales");
        }
コード例 #2
0
        public static void FirstVsFirstOrDefault()
        {
            var employees = new SampleData().GetEmployees();

            ////throws error
            //var empdata = employees.Where(e => e.EmployeeId == 200).First();

            var empdata1 = employees.Where(e => e.EmployeeId == 200).FirstOrDefault();

            if (empdata1 == null)
            {
                Console.WriteLine("Employee not found");
            }

            Console.Read();
        }
コード例 #3
0
        public static void IndexedQueries()
        {
            var employees = new SampleData().GetEmployees();

            //var selectedEmps = employees.Where(emp => emp.Department == "Sales");
            var selectedEmps = employees.Where((emp, index) => ((index != 0) ? true : false));

            foreach (var emp in selectedEmps)
            {
                Console.WriteLine("Employee Name: " + emp.EmployeeName);

            }
            Console.Read();
        }