static void Main(string[] args) { IEnumerable<Employee> developers = new Employee[] { new Employee { Id = 1, Name = "vsl"}, new Employee { Id = 2, Name = "kst"} }; IEnumerable<Employee> sales = new List<Employee>() { new Employee { Id = 3, Name = "kel"} }; var query = developers.Where(e => e.Name.Length < 4) .OrderByDescending(e => e.Name) .Select(e => e); var query2 = from developer in developers where developer.Name.Length < 4 orderby developer.Name select developer; foreach (var employee in query) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Rafa" }, new Employee { Id = 2, Name = "Roger" }, new Employee { Id = 2, Name = "Andy" } }; IEnumerable <Employee> Sales = new List <Employee>() { new Employee { Id = 3, Name = "Djokovic" } }; int cntEmpl = developers.Count(); Console.WriteLine(cntEmpl); IEnumerator <Employee> enumerator = developers.GetEnumerator(); foreach (var emp in developers.Where(e => e.Name.StartsWith("R"))) { Console.WriteLine(emp.Name); } Console.ReadLine(); }
static void Main(string[] args) { var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } Console.ReadLine(); }
static void Main(string[] args) { IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; foreach (var employee in developers.Where(e => e.Name.StartsWith("S"))) { Console.WriteLine(employee.Name); } Console.ReadKey(); }
static void Main(string[] args) { IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; foreach (var employee in developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name)) { Console.WriteLine(employee.Name); } //Console.WriteLine(developers.Count()); //IEnumerator<Employee> enumerator = developers.GetEnumerator(); //while (enumerator.MoveNext()) //{ // Console.WriteLine(enumerator.Current.Name); //} }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> sum = (x, y) => x + y; Action <int> write = x => Console.WriteLine(x); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); foreach (var employee in query) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { // Func indicates lambda definition // takes an int and return an int Func <int, int> square = x => x * x; Console.WriteLine(square(3)); Console.WriteLine("**********"); Func <int, int, int> add = (x, y) => x + y; Console.WriteLine(add(3, 4)); Console.WriteLine("**********"); Func <int, int, int> add2 = (x, y) => { int temp = x + y; return(temp); }; Console.WriteLine("**********"); // returns void Action <int> write = x => Console.WriteLine(x); write(999); Console.WriteLine("**********"); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Julien" }, new Employee { Id = 2, Name = "Bibi" } }; Console.WriteLine(developers.MyCount()); Console.WriteLine("**********"); IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Lulu" } }; IEnumerator <Employee> enumerator = developers.GetEnumerator(); while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current.Name); } Console.WriteLine("**********"); foreach (var Employee in developers.Where(e => e.Name.StartsWith('B'))) { Console.WriteLine(Employee.Name); } }
static void Main(string[] args) { Func <int, int> Square = x => x * x; //Alternate local function //int Square(int x) => x * x; Console.WriteLine($"Square of 5 is: {Square(5)}"); Func <int, int, int> Add = (x, y) => x + y; Console.WriteLine($"SUM of 5 & 7 is: {Add(5, 7)}"); Action <int> write = x => Console.WriteLine(x); //Alternate local function //void write(int x) => Console.WriteLine(x); write(Square(Add(4, 4))); //Array of developers of Employee Type Employee[] developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; //Array of sales persons of Employee Type IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; Console.WriteLine($"Total number of developers is: {developers.Count()}"); var query_1 = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query_2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query_1) { Console.WriteLine(employee.Name); } Console.WriteLine("\n***\n"); foreach (var employee in query_2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { Func <int, int> f = number => number * number; // computing square Func <int, int, int> add = (n, m) => (n + m); // computing addition //* in Func the last data type is meant for return type whe Console.WriteLine(square(add(10, 0))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Antrish" }, new Employee { Id = 2, Name = "Anand" }, new Employee { Id = 3, Name = "Ajeet" }, }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 4, Name = "Pawan" }, new Employee { Id = 4, Name = "Chandra" }, }; //foreach (Employee emp in sales) //{ // Console.WriteLine(emp.Name); //} //IEnumerator<Employee> enumerator = sales.GetEnumerator(); //Console.WriteLine(developers.GetCount()); // extention method getCount //while (enumerator.MoveNext()) //{ // Console.WriteLine(enumerator.Current.Name); //} //foreach (var emp in developers.Where(e => e.Name.EndsWith("d"))) //{ // Console.WriteLine(emp.Name); //} var query = developers.Where(e => e.Name.Length >= 5).OrderByDescending(e => e.Name); var query2 = from developer in developers where developer.Name.Length >= 5 orderby developer.Name descending select developer; foreach (var emp in query) { Console.WriteLine(emp.Name); } Console.WriteLine("-----------------------------------------"); foreach (var emp in query2) { Console.WriteLine(emp.Name); } }
static void Main(string[] args) { Func <double, double> square = x => x * x; Func <double, double, double, double> rectangleArea = (l, w, h) => l * w * h; Func <double, double, double> triangleArea = (b, h) => { double area = .5 * (b * h); return(area); }; Action <int> write = x => Console.WriteLine(x); write(1); Console.WriteLine(square(3)); Console.WriteLine(rectangleArea(4, 5, 6)); var developers = new Employee[] { new Employee { Id = 1, Name = "Jairoh" }, new Employee { Id = 2, Name = "Deb" }, new Employee { Id = 3, Name = "Jack" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Darl" } }; // IEnumerator<Employee> enumerator = developers.GetEnumerator(); // while (enumerator.MoveNext()) // { // var employee = enumerator.Current; // Console.WriteLine(employee.Name); // } // Method Syntax (using lambda expressions) var jDevelopers = developers.Where(d => d.Name.StartsWith("J")) .OrderBy(d => d.Name).ToList(); jDevelopers.ForEach(d => Console.WriteLine($"{d.Id} {d.Name}")); // Query Syntax var jDevelopers2 = (from dev in developers where dev.Name.StartsWith("J") orderby dev.Name select dev).ToList(); Console.ReadLine(); }
static void Main(string[] args) { Func <int, int> square = x => x * x; //last type is the return type, everything before is parameter // so this takes an int, return an int Func <int, int, int> add = (x, y) => x + y; //there's two parameters, you need paranthesis (x,y) // you can use curly braces, but you have to use return Action <int> write = x => Console.WriteLine(x); //returns void write(square(add(3, 5))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; //Using var instead of explicitely saying something is IEnumerable<Employee> var query = developers.Where (e => e.Name.Length == 5).OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; //^ same thing foreach (var employee in query2) { Console.WriteLine(employee.Name); } //^basically we are putting a func type in there instead of the one below }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" }, }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; //Console.WriteLine(developers.Count()); // METHOD SYNTAX var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name) .Select(e => e); // this line is optional // QUERY SYNTAX var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query) { Console.WriteLine(employee.Name); } foreach (var employee in query2) { Console.WriteLine(employee.Name); } // // longer way to write a foreach, essentially doing it yourself // IEnumerator<Employee> enumerator = developers.GetEnumerator(); // while (enumerator.MoveNext()) { // Console.WriteLine(enumerator.Current.Name); // } }
static void Main(string[] args) { // Anonymous Methos -- Delegate -- Lambda Expression Func <int, int> square = x => x * x; Console.WriteLine(square(3)); Func <int, int, int> sum = (x, y) => x + y; Action <int> Write = x => Console.WriteLine(x); Write(square(sum(3, 5))); //*** IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Ismail" }, new Employee { Id = 2, Name = "Badr" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Issam" } }; /*IEnumerator<Employee> enumerable = sales.GetEnumerator(); * * Console.WriteLine(developers.Count()); * * while (enumerable.MoveNext()) * { * Console.WriteLine(enumerable.Current.Name); * }*/ var query = developers.Where(e => e.Name.Length == 4) .OrderBy(e => e.Name).Select(e => e); var query2 = from developer in developers where developer.Name.Length == 4 orderby developer.Name select developer; foreach (var employee in query) { Console.WriteLine(employee.Name); } }
public static void Main(string[] args) { // Funcs made for delegates Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; // Action Action <int> write = x => Console.WriteLine(x); // write(square(add(3, 5))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scrot" }, new Employee { Id = 2, Name = "Chris" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; //Console.WriteLine(developers.Count()); //IEnumerator<Employee> enumerator = developers.GetEnumerator(); //while (enumerator.MoveNext()) //{ // Console.WriteLine(enumerator.Current.Name); //}; //foreach (var person in developers.Where(delegate (Employee employee) //{ // return employee.Name.StartsWith("S"); //})) //{ // Console.WriteLine(person.Name); //} var query1 = developers.Where(e => e.Name.Length == 5).OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length > 2 orderby developer.Name descending select developer; foreach (var person in query2) { Console.WriteLine(person.Name); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => { int temp = x + y; return(temp); }; Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "SFoo5" }, new Employee { Id = 2, Name = "Bar45" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Ricky Bobby" } }; //foreach (var person in developers) //{ // Console.WriteLine(person.Name); //} //Console.WriteLine(developers.OrderBy(x => x.Id)); //IEnumerator<Employee> enumerator = developers.GetEnumerator(); //while (enumerator.MoveNext()) //{ // Console.WriteLine(enumerator.Current.Name); //} var query = developers.Where(e => e.Name.Length == 5) .OrderByDescending(e => e.Name) .Select(e => e); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name descending select developer; foreach (Employee employee in query2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; //Writing the body in lambda exp Func <int, int, int> sub = (x, y) => { int temp = x - y; return(temp); }; Action <int> write = x => Console.WriteLine(x); write(square(add(5, 6))); write(square(sub(8, 4))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; //Method Syntax var query = developers.Where(e => e.Name.Length == 5) .OrderByDescending(e => e.Name) .Select(e => e); //Query Syntax var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name descending select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } //Console.WriteLine(developers.Count()); //using linq is commented. this method is rewritten using extension. //IEnumerator<Employee> enumerator = developers.GetEnumerator(); //while(enumerator.MoveNext()) //{ // Console.WriteLine(enumerator.Current.Name); //} }
static void Main(string[] args) { //Func<int, int> Square = x => x * x; //Lambda Expression int square(int x) => x * x; //Func<int, int, int> add = (x, y) => x + y; int add(int x, int y) => x + y; //Action<int> write = x => Console.WriteLine(x); void write(int x) => Console.WriteLine(x); int n = 5, x1 = 5, y1 = 16; //Console.WriteLine($"Square of {n} is {Square(n)}"); //Console.WriteLine($"{x1} plus {y1} is {add(x1, y1)}"); write(square(add(x1, y1))); var developers = new Employee[] { new Employee() { Id = 1, Name = "Scott" }, new Employee() { Id = 2, Name = "Chirs" } }; var sales = new List <Employee>() { new Employee() { Id = 3, Name = "Alex" } }; //Console.WriteLine(sales.Count()); //foreach (var person in developers.Where(NameStartsWithS)) //foreach (var person in developers.Where(e => e.Name.StartsWith("S"))) var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query2 = from person in developers where person.Name.Length == 5 orderby person.Name select person; foreach (var person in query2) { Console.WriteLine(person.Name); } Console.ReadKey(); }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; Action <int> write = x => Console.WriteLine(x); write(add(2, 2)); Console.WriteLine(add((square(5)), (square(4)))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Ales" }, new Employee { Id = 4, Name = "Olek" } }; /*Console.WriteLine(developers.Count()); * IEnumerator<Employee> enumerator = sales.GetEnumerator(); * while (enumerator.MoveNext()) * { * Console.WriteLine(enumerator.Current.Name); * Console.ReadKey(); * } */ //method syntax var query = developers.Where(e => e.Name.StartsWith("S")) .Where(e => e.Name.Length >= 4) .OrderBy(e => e.Name); //query syntax var query2 = from developer in developers where developer.Name.Length == 5 where developer.Name.StartsWith("S") orderby developer.Name select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); Console.ReadKey(); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => { var temp = x + y; return(temp); }; Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; /* * foreach (var employee in developers.Where(delegate (Employee employee) * { * return employee.Name.StartsWith("S"); * })) * { * Console.WriteLine(employee.Name); * } */ var query = developers.Where(e => e.Name.Length == 5) .OrderByDescending(e => e.Name) .Select(e => e); //Optional syntax var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name descending select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { //Last paramenter corresponds with the return type, all other are the parameters' Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => { int temp = x + y; return(temp); }; //Action methods always return a void, therefore <x> corresponds to the parameters Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; //This is an example for Implicit Typing //Use in local variables (imposible to use to define variables or fields in a class) var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; //Method Syntax (Call Extension Methods) var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); //Query Sintax (from...select...) var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query) { Console.WriteLine(employee.Name); } Console.ReadKey(); }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); var developers = new Employee[] { new Employee { Id = 1, Name = "Wes" }, new Employee { Id = 2, Name = "Nate" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Stephen" } }; // foreach( var employee in developers.Where(NameStartsWithS) ) // { // System.Console.WriteLine(employee.Name); // } // foreach( var employee in developers.Where( delegate (Employee employee) // { // return employee.Name.StartsWith("S"); // })) // { // System.Console.WriteLine(employee.Name); // } var query = developers.Where(e => e.Name.Length == 3).OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 3 orderby developer.Name select developer; foreach (var employee in query2) { System.Console.WriteLine(employee.Name); } }
static void Main(string[] args) { //delegate type Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => { int temp = x + y; return(temp); }; //always returns void Action <int> write = x => Console.WriteLine(x); //utilizing the write action write(square(add(3, 5))); //IEnumerable<Employee> can use var for implicit typing var developers = new Employee[] { new Employee { EmployeeId = 1, EmployeeName = "Scott" }, new Employee { EmployeeId = 2, EmployeeName = "Chris" } }; //IEnumerable<Employee> can use var for implicit typing var sales = new List <Employee>() { new Employee { EmployeeId = 3, EmployeeName = "Alex" } }; //Method syntax var query = developers.Where(e => e.EmployeeName.Length == 5) .OrderByDescending(e => e.EmployeeName) .Select(e => e).Count(); //Query syntax var queryTwo = from developer in developers where developer.EmployeeName.Length == 5 orderby developer.EmployeeName descending select developer; foreach (var employee in queryTwo) { Console.WriteLine(employee.EmployeeName); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => { int temp = x + y; return(temp); }; Action <int> write = x => Console.WriteLine(x); write(square(add(3, 5))); //Employee[] developers = new Employee[] var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; //List<Employee> sales = new List<Employee>() var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } Console.ReadLine(); }
static void Main(string[] args) { //this method returns type of the last parameter Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; //this method returns void Action <int> write = x => Console.WriteLine(x); WriteLine(square(add(3, 5))); write(5); WriteLine(); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var Sales = new List <Employee> { new Employee { Id = 3, Name = "Alex" } }; //method sintax of writing linq var query = developers.Where(e => e.Name.Length == 5).OrderByDescending(e => e.Name); //query sintax of writing linq var query2 = from employee in developers where employee.Name.Length == 5 orderby employee.Name descending select employee; foreach (var empl in query2) { WriteLine(empl.Name); } WriteLine("\nPress any key to exit..."); ReadKey(); }
static void Main(string[] args) { int square(int x) => x * x; int add(int x, int y) { int temp = x + y; return(temp); } IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Warren" }, new Employee { Id = 2, Name = "Liam" }, new Employee { Id = 3, Name = "Steven" } }; Console.WriteLine(square(add(3, 5))); var sales = new List <Employee>() { new Employee { Id = 4, Name = "Alan" } }; var query = developers.Where(e => e.Name.Length == 6) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 6 orderby developer.Name descending select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; Action <int> write = x => Console.WriteLine(x); Console.WriteLine(square(add(3, 5))); write(square(add(3, 5))); IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 2, Name = "Lucian" }, new Employee { Id = 1, Name = "Dragos" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Claudiu" } }; var query = developers.Where(e => e.Name.Length == 6) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var person in query) { Console.WriteLine(person.Name); } Console.WriteLine(sales.Count()); IEnumerator <Employee> enumerator = sales.GetEnumerator(); while (enumerator.MoveNext()) { Console.WriteLine(enumerator.Current.Name); } }
private static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (a, b) => { int temp = a + b; return(temp); }; Action <int> write = x => Console.WriteLine(x); Console.WriteLine(square(3)); write(square(add(3, 5))); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; var query1 = developers .Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; // => is read as 'goes to' foreach (var employee in query2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { Func <int, int> duplicate = x => x * x; Func <int, int, int> func2 = (x, y) => x + y; Action <string> write = x => Console.WriteLine(x); write("TESTE"); Console.WriteLine(duplicate(10)); Console.WriteLine(func2(10, 2)); var developers = new Employee[] { new Employee { Id = 1, Name = "Daniel" }, new Employee { Id = 2, Name = "Karina" }, new Employee { Id = 3, Name = "Karin" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; var query = developers.Where(e => e.Name.Length == 5) .OrderByDescending(x => x.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name descending select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { Func <int, int> square = x => x * x; Func <int, int, int> add = (x, y) => x + y; Func <int, int, int, int> add3 = (x, y, z) => { return(x + y + z); }; Console.WriteLine(square(add(3, 5))); var developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; var sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; Console.WriteLine(developers.Count()); // Essentially writes a foreach statement from scratch using IEnumerator // IEnumerator<Employee> enumerator = developers.GetEnumerator(); // while (enumerator.MoveNext()) // { // Console.WriteLine(enumerator.Current.Name); // } foreach (var employee in developers.Where(e => e.Name.StartsWith("S"))) { Console.WriteLine(employee.Name); } }
static void Main(string[] args) { IEnumerable <Employee> developers = new Employee[] { new Employee { Id = 1, Name = "Scott" }, new Employee { Id = 2, Name = "Chris" } }; IEnumerable <Employee> sales = new List <Employee>() { new Employee { Id = 3, Name = "Alex" } }; Console.WriteLine(developers.Count()); //foreach (var employee in developers.Where( // e => e.Name.StartsWith("S"))) //{ // Console.WriteLine(employee.Name); //} var query = developers.Where(e => e.Name.Length == 5) .OrderBy(e => e.Name); var query2 = from developer in developers where developer.Name.Length == 5 orderby developer.Name select developer; foreach (var employee in query2) { Console.WriteLine(employee.Name); } }