CSharp · Console
// C# Eval Expression
// Doc: https://eval-expression.net/linq-dynamic
// @nuget: Z.Expressions.Eval
/*
## LINQ SkipWhileDynamic Method
The LINQ SkipWhileDynamic method bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements. You can use a dynamic string expression to create the predicate.
In this example, we will create a list of product and ordering them descending per type and skipping all `paid` products (instead of using a `where` clause).
See more: https://eval-expression.net/linq-dynamic
*/
using System;
using System.Collections.Generic;
using System.Linq;
using Z.Expressions;
public class Program
{
public static void Main()
{
var product1 = new Product() { Name = "C# Eval Expression", Url = "https://eval-expression.net/", Type = "Paid" };
var product2 = new Product() { Name = "Dapper Plus", Url = "https://dapper-plus.net/", Type = "Paid" };
var product3 = new Product() { Name = "Entity Framework Extensions", Url = "https://entityframework-extensions.net/", Type = "Paid" };
var product4 = new Product() { Name = ".NET Fiddle", Url = "https://dotnetfiddle.net/", Type = "Free" };
var product5 = new Product() { Name = "SQL Fiddle", Url = "https://sqlfiddle.com/", Type = "Free" };
var product6 = new Product() { Name = "ZZZ Code AI", Url = "https://zzzcode.ai/", Type = "Free" };
var list = new List<Product>() { product1, product2, product3, product4, product5, product6 };
var skipWhileList = list.OrderByDescendingDynamic("x => x.Type").SkipWhileDynamic("x => x.Type == 'Paid'").ToList();
FiddleHelper.WriteTable("1 - skipWhileList:", skipWhileList);
}
public class Product
{
public string Name { get; set; }
public string Url { get; set; }
public string Type { get; set; }
}
}