Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8884977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:11:47+00:00 2026-06-14T21:11:47+00:00

var myDic = new SortedDictionary<DateTime,int> () { { new DateTime(0), 0 }, { new

  • 0
var myDic = new SortedDictionary<DateTime,int> () 
                { { new DateTime(0), 0 },
                  { new DateTime(1), 1 },
                  { new DateTime(2), 1 },
                  { new DateTime(3), 0 },
                  { new DateTime(4), 0 },
                  { new DateTime(5), 2 }
                };

How can group these items (with a LINQ request) like this :

group 1 : 
  startDate: 0, endDate:0, value:0
group 2 : 
  startDate: 1, endDate:2, value:1
group 3 : 
  startDate: 3, endDate:4, value:0
group 4 : 
  startDate: 5, endDate:5, value:2

group are defined by contiguous date and same values.

Is it possible with a groupby ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:11:48+00:00Added an answer on June 14, 2026 at 9:11 pm

    Just use a keyGenerating function. This example presumes your dates are already ordered in the source with no gaps.

    int currentValue = 0;
    int groupCounter = 0;
    
    Func<KeyValuePair<DateTime, int>, int> keyGenerator = kvp =>
    {
      if (kvp.Value != currentValue)
      {
        groupCounter += 1;
        currentValue = kvp.Value;
      }
      return groupCounter;
    }
    
    List<IGrouping<int, KeyValuePair<DateTime, int>> groups =
      myDictionary.GroupBy(keyGenerator).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an element like this: var myDiv = new Element('div'); myDiv.update('Hello!'); I
I'm writing a query that looks like this: var TheOutput = (from x in
I have a query that looks like this: var TheQuery = (from t in
I can make a obj to use the canvas to draw like this: MyObj.myDiv
I'm writing a query like this: var TheQuery = (from t in MyDC.Table1 where
I am trying this var newNum = some new number; $(#myDiv fieldset:last).find(':input').attr('name', $(this).attr('name') +
Consider the following code: var myDict = new Dictionary<string, int>(); myDict.Add(Key1, 1); myDict.Add(Key2, 2);
I have a query that looks like this: var TheOutput = from u in
var ref1 = new Firebase(http://gamma.firebase.com/myuser/123,456); ref1.set(123,456); var on1 = ref1.on(value, function(snapshot) { console.log(snapshot.val()); });
var fruit = [apple,pear,pear,pear,banana]; How do I remove all pear fruit from this array?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.