If you do not really put down the past, there will be no tomorrow.
Program.cs
Class Program {static void Main (string[] args) {string[] companies = {"Integrated Instant messenger", "Alpine ski Home", "Shaoxing Srich", "City Power and Lighting", "Coho Winery", "intruders from all over the world", "Graphic Design Institute", "Adventure Project", "Humongous Insurance", "Woodgrove Bank", "Margie Travel", "
Northwind Traders, "Blue Yonder Airlines", "Trey Research", "Telephone Company", "Wing-tip Toys", "Lucerne published", "fourth session Coffee"}; The IQueryable data to query iqueryable<string> Queryabledata = companies.
Asqueryable<string> ();
Expression tree parameter ParameterExpression PE = Expression.parameter (typeof (String), "Company"); -------------------------------------------------------------------------------------------------------//WH Ere (company =>. ToLower () = = "Coho Winery" | | Company.
Length > 8)//Create a methodcallexpression that represents a call to an instance method without parameters. Create a presentation expression "company."
ToLower () = = "Coho Winery" expression tree. Expression left = Expression.call (PE, typeof (String). GetMethod ("ToLower", System.Type.EmptyTypes));
Expression right = Expression.constant ("Coho Winery");
Expression e1 = Expression.equal (left, right); Create a presentation expression "company." length> 8 expression Tree left = Expression.property (PE, typeof (String).
GetProperty ("Length"));
right = Expression.constant (8, typeof (int));
Expression e2 = Expression.greaterthan (left, right); Creates a binaryexpression that evaluates the condition//combination expression tree of the second operand to create a presentation expression, only if the first operand evaluates to False (company. ToLower () = = "Coho Winery" | | Company.
Length> 8) "is an expression tree.
Expression predicatebody = Expression.orelse (e1, E2); Create a representation expression Queryabledata.where company =>. ToLower () = = "Coho Winery" | | Company.
Length> 8) "is an expression tree.
Methodcallexpression wherecallexpression = Expression.call (typeof (Queryable), "Where", New type[] {queryabledata.elementtype}, queryabledata.expression, Expressi On. Lambda<func< string, bool>> (Predicatebody, new parameterexpression[] {PE}); -------------------------------------------------------------------------------------------------------//Create An expression tree ' wherecallexpression that represents an expression.
By (company => Company) ' Methodcallexpression orderbycallexpression = Expression.call ( typeof (Queryable), "by", new type[] {queryabledata.elementtype, queryabledata.elemen Ttype}, Wherecallexpression, Expression.lambda<func<string, string>> (PE, new
parameterexpression[] {PE})); //-------------------------------------------------------------------------------------------------------
//
Creates an executable query from the expression tree.
iqueryable<string> results = queryabledata.provider.createquery<string> (orderbycallexpression);
Enum result foreach (string company in results) { Console.WriteLine (company);
} console.readline (); }
}
run the results as shown in figure: