To.Take () or not .Take (), this is a question

I have a collection representing a collection (M, F) for each year.

To project the population over time, I must first make calculations with women so that I can calculate the percentage of newborn men and women based on the statistical constant of fertility in masculinity.

However, I have the first matrix that contains both men and women under the age of one year.

// Where 1 is the evaluation Id and 2009 the year I want the 
// initial population information for.
IList<AnnualPopulation> initialPopulation = 
    LoadMatrix<AnnualPopulation>(1, 2009);

Now, to first predict a population of women, I use the following:

IList<AnnualPopulation> initialWomenPopulation = (
        from w in initialPopulation
        where String.Equals("F", w.Gender)
        select w
    ).FirstOrDefault();

And I have to take into account mortality rates both for the current (initial year (2009)) and for the year for which I want to project, from which I already have a mortality rate for each year.

IList<AnnualDeathRate> deathRates = LoadMatrix<AnnualDeathRate>(1, 2009)

2009 . , 2009 2010, , Linq.

AnnualDeathRate[] femaleDeathRates = (
        from fdr in deathRates
        where (string.Equals("F", fdr.Gender))
        select fdr
    ).TakeWhile(dr => 
        initialWomenPopulation.Year == dr.Year || 
        dr.Year == initialWomenPopulation.Year + 1
    ).ToArray()

  • , .Take(2) where dr.Year?
  • ?
  • ?
+5
2

# 1 , . , ( ), (, , , )

, № 1 ( TakeWhile). , 2 , , , .

var numbers = new[] {2, 3, 1, 4};
Console.WriteLine("TakeWhile");

foreach(var n in numbers.TakeWhile(x => x == 1 || x == 2))
{
    Console.Write(n);
}
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("WhereTake2");

foreach (var n in numbers.Where(x => x == 1 || x == 2).Take(2))
{
    Console.Write(n);
} 

TakeWhile
2

WhereTake2
21
+1

TakeWhile where , , ? , , , TakeWhile , IMO.

+1

All Articles