本文整理汇总了C#中List.TakeWhile方法的典型用法代码示例。如果您正苦于以下问题:C# List.TakeWhile方法的具体用法?C# List.TakeWhile怎么用?C# List.TakeWhile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List.TakeWhile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main()
{
var collection = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
int first = collection.FirstOrDefault(Even);
Console.WriteLine(first);
Console.WriteLine(collection.FirstOrDefault(x => x > 4));
var allEven = collection.TakeWhile(Even);
Console.WriteLine(string.Join(" ",allEven));
Console.WriteLine(string.Join(" ", collection.TakeWhile(x => x < 10)));
collection.ForEach(Console.WriteLine);
}
示例2: Main
static void Main()
{
List<int> collection = new List<int>() { 1, 2, 3, 6, 11, 20 };
Console.WriteLine(collection.FirstOrDefault(x => x > 7));
Console.WriteLine(string.Join(", ", collection.TakeWhile(x => x < 5)));
collection.ForEach(Console.WriteLine);
}
示例3: Main
static void Main(string[] args)
{
var nums = new List<int>() {1, 2, 3, 4, 5, 6, 7};
var result = nums.TakeWhile(e => e < 6);
Console.WriteLine(string.Join(", ", result));
}
示例4: filterByEnding
private static List<Solution> filterByEnding(Solution end, List<Solution> solutions)
{
if (end != null)
{
solutions = solutions.TakeWhile(x => x != end).Where(end.DependsOn).ToList();
solutions.Add(end);
}
return solutions;
}
示例5: ProductRepository
public ProductRepository()
{
_products = new List<Product>(new Product[]{
new Product {Name = "Kayak", Category = "Watersports", Price = 275M},
new Product {Name = "Lifejacket", Category = "Watersports", Price = 48.95M},
new Product {Name = "Soccer ball", Category = "Soccer", Price = 19.50M},
new Product {Name = "Corner flag", Category = "Soccer", Price = 34.95M}
});
_products.TakeWhile(p => p.Name == "Kayak");
}
示例6: Lista
public JsonResult Lista()
{
var lista = new List<int> ();
for (int i = 0; i < 50; i++) {
lista.Add (i);
}
var tes = lista.TakeWhile(a => a < 15).LastOrDefault();
return Json(tes, JsonRequestBehavior.AllowGet);
}
示例7: UlongPrimes
public static IEnumerable<ulong> UlongPrimes() {
var memoized = new List<ulong>();
var primes = PotentialUlongPrimes().Where(x => {
double sqrt = Math.Sqrt(x);
return memoized
.TakeWhile(y => y <= sqrt)
.All(y => x % y != 0);
});
foreach (var prime in primes) {
yield return prime;
memoized.Add(prime);
}
}
示例8: Main
static void Main()
{
List<int> list = new List<int>()
{
1, 12, 19, 13, 100, 1, 1000, 13, 13, 1
};
IEnumerable<int> smallNums = list.TakeWhile(n => n < 100);
foreach (var num in smallNums)
{
Console.WriteLine(num);
}
}
示例9: Delete
public int Delete(string name, string producer)
{
var productsWithGivenName = new List<Product>(
productsByName[name]);
var temp = productsWithGivenName.TakeWhile(x => x.Producer == producer);
var count = temp.Count();
foreach (var product in temp)
{
productsByName.Remove(product.Name);
productsByPrice.Remove(product);
productsByProducer.Remove(producer);
}
return count;
}
示例10: Primes4
public static IEnumerable<int> Primes4(int count)
{
var memoized = new List<int>();
var primes = PotentialPrimes(count).Where(x =>
{
var sqrt = Math.Sqrt(x);
return !memoized
.TakeWhile(y => y <= sqrt)
.Any(y => x % y == 0);
});
foreach (var prime in primes)
{
yield return prime;
memoized.Add(prime);
}
}
示例11: Get
public static IEnumerable <long> Get ()
{
var temp = new List <long> ();
var current = 1L;
while (true)
{
current++;
var sqrt = Math.Sqrt (current);
if (temp
.TakeWhile (x => x <= sqrt)
.Any (x => current % x == 0))
continue;
temp.Add (current);
yield return current;
}
}
示例12: Main
static void Main()
{
Action<int> printNumberAction = Console.WriteLine;
printNumberAction(10);
var students = new List<Student>()
{
new Student("Pesho", 23),
new Student("Sasho", 18),
new Student("Ivan", 34)
};
Student ivan = students.FirstOrDef(Hasname);
Console.WriteLine(ivan.Name + " " + ivan.Age);
var nums = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
nums.ForEachH();
var smallNums = nums.TakeWhile(IsSmallerThan);
Console.WriteLine(String.Join(", ", smallNums));
}
示例13: Append
public void Append(TableDataDesc table)
{
var rows = new List<RowDesc>();
foreach(var scriptedRow in table.ScriptedData)
{
var row = DataDescFactory.CreateRowDescriptor(scriptedRow, table.PrimaryColumns);
rows.Add(row);
}
var gen = new RowScriptGen();
//Header
var header = rows.TakeWhile(r => false == r is InsertRowDesc);
//_sb.Append(gen.GenerateScript(header));
_sb.AppendFormat("{0}{1}", gen.GenerateScript(header), Environment.NewLine);
//Data
var data = rows.Where(r => r is InsertRowDesc).Select(r => r as InsertRowDesc);
_sb.AppendFormat("{0}{1}", gen.GenerateMergeScript(data, true), Environment.NewLine);
//Footer
var footer = rows.Skip(header.Count() + data.Count());
_sb.AppendFormat("{0}{1}", gen.GenerateScript(footer), Environment.NewLine);
}
示例14: ProbeScreenBounds
private IList<Rectangle> ProbeScreenBounds()
{
var screenBoundsList = new List<Rectangle>();
foreach (Screen screen in Screen.AllScreens)
{
Rectangle currentBounds = DpiHelper.ConvertPixelsToDIPixels(screen.Bounds);
if (screenBoundsList.Count == 0)
{
screenBoundsList.Add(currentBounds);
continue;
}
int index = screenBoundsList.TakeWhile(bounds => (currentBounds.Top >= bounds.Top) && (currentBounds.Left >= bounds.Left)).Count();
screenBoundsList.Insert(index, currentBounds);
}
return screenBoundsList;
}
示例15: Generate
public IEnumerable<long> Generate()
{
var primes = new List<long>();
yield return 2;
yield return 3;
var value = 5L;
var add4 = false;
while(true)
{
var maxFactor = (int)Math.Sqrt(value) + 1;
if (!primes.TakeWhile(prime => prime <= maxFactor).Any(prime => value % prime == 0))
{
primes.Add(value);
yield return value;
}
value += (add4 ? 4 : 2);
add4 = !add4;
}
}