score:4

Accepted answer

here's one way you could do it with groupjoin:

var groupeddates = dates
    .select((date, index) => new { date = date, index = index })
    .groupjoin(
        numbers,
        datewithindex => datewithindex.index,
        num => (num - 1) / 2,
        (datewithindex, nums) => new[] 
        { 
            new { date = datewithindex.date, number = nums.first() },
            new { date = datewithindex.date, number = nums.last() }
        })
    .selectmany(grp => grp);

example: https://dotnetfiddle.net/2iikhj

here's how this works:

  1. project the dates list into a new sequence containing the index of each date and the date itself
  2. groupjoin that collection with the list of numbers. to correlate the two, use the index we got from step 1 for the date, and (num - 1) / 2, since index is zero-based.
  3. to build the reusult, create a new array containing two items, one for each number associated with the date.
  4. finally, call selectmany to flatten the sequence.

score:1

i think best way to map values in c# is to use dictionary<key,value>. you can have a one-to-many relationship -- that is, one date has several sessions. the code would look like this:

dictionary<datetime, list<int>> dicdatesesstion = new dictionary<datetime, list<int>>();

score:2

assumed that listi.length == 2*listd.length

list<int> listi = new int[] { 1, 2, 3, 4, 5, 6 }.tolist();
list<datetime> listd = new datetime[] { datetime.parse("5-10-2014"), datetime.parse("6-10-2014"), datetime.parse("7-10-2014") }.tolist();

ienumerable<tuple<datetime, int>> result = 
    enumerable.range(0, listi.count)
    .select(x => new tuple<datetime, int>(listd[x / 2], listi[x]));

score:2

if you develop your project with .net 4.0 or higher versions you can use zip().

ienumerable<int> keys = new list<int>() { 1, 2, 3, 4, 5, 6 }; // your keys
ienumerable<datetime> values = new list<datetime>() { datetime.parse("5 - 10 - 2014"), datetime.parse("6 - 10 - 2014"), datetime.parse("7 - 10 - 2014") }; // your values
var mappeddictionary = keys.zip(values, (k, v) => new {
            k,
            v
        }).todictionary(x => x.k, x => x.v);

this link proves how it works.. https://dotnetfiddle.net/ykyf8s

score:4

here's a simple solution:

dates is a list of datetime and sessions is a list of int.

var result = sessions.select((session,i) => 
                      new{session = session, date = dates[i/2]});

the result contains an ienumerable of anonymous objects, you can access its properties like this:

foreach(var sessiondate in result)
{
   var date = sessiondate.date;
   var session = sessiondate.session.
}

Related Query

More Query from same tag