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 8925427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:41:35+00:00 2026-06-15T07:41:35+00:00

hello guys I’m doing a little self learning and i have come across of

  • 0

hello guys I’m doing a little self learning and i have come across of problem that seems to have stumped me for the time being i figuere someone here im sure has already encountered something similar to this in the past. i have an array list of 1-10

public List<int> ValueArrays = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

im trying to get the sum of every number groups of 6 but i’m just stuck.
for example i want

[1,2,3,4,5,6]
[1,3,4,5,6,7]
[1,4,5,6,7,8] etc...

i have written some code but im just stumbling on my feet here.

private void runbtn_Click(object sender, EventArgs e)
        {
            int thisTotal;
            //Object ListOfNumbersToCompareTo = new Object[];
            List<int> fiveEl = new List<int> { }; //= ValueArrays.GetRange(1, 5);//target a group of 5
            List<int> test2 = new List<int> { };
            //test2.AddRange(fiveEl);

            //thisTotal = SumRange(fiveEl);
             int groupSize = 5;





            for (int i = 0; i < ValueArrays.Count; i++)
            {

                fiveEl=ValueArrays.GetRange(i+1, 5);
                currentNum = ValueArrays[i];
                fiveEl.Add(currentNum);


                for (int x = 0; x < 1; x++)
                {
                    thisTotal = SumRange(fiveEl);

                    //fiveEl = ValueArrays.GetRange(x, groupSize);
                    //fiveEl.Add(currentNum);
                    //fiveEl.RemoveRange(x, groupSize); ;
                }




            }
}

can someone give me a code snippet or point me in the right direction?
Thanks in advance.

  • 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-15T07:41:37+00:00Added an answer on June 15, 2026 at 7:41 am

    Personally I’d write it like this:

    var values = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    var groupsOfSix = values.Subsequences().Where(s => s.Count() == 6);
    

    And then of course you can use .Sum() on each of the subsequences thus generated.

    This uses an extension method I wrote some time ago, which generates all subsequences of an IEnumerable<T>. This solution is not the most speedy possible, but by golly does it make the code easy to read and obviously correct, and on an input list of just 10 elements it’s way fast enough.

    Here’s the Subsequences function:

    /// <summary>
    /// Returns all subsequences of the input <see cref="IEnumerable&lt;T&gt;"/>.
    /// </summary>
    /// <param name="source">The sequence of items to generate subsequences of.</param>
    /// <returns>A collection containing all subsequences of the input <see cref="IEnumerable&lt;T&gt;"/>.</returns>
    public static IEnumerable<IEnumerable<T>> Subsequences<T>(this IEnumerable<T> source)
    {
        if (source == null)
            throw new ArgumentNullException("source");
        // Ensure that the source IEnumerable is evaluated only once
        return subsequences(source.ToArray());
    }
    
    private static IEnumerable<IEnumerable<T>> subsequences<T>(IEnumerable<T> source)
    {
        if (source.Any())
        {
            foreach (var comb in subsequences(source.Skip(1)))
            {
                yield return comb;
                yield return source.Take(1).Concat(comb);
            }
        }
        else
        {
            yield return Enumerable.Empty<T>();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello guys i have a little problem i get an error: File C:\Users\kokki\Desktop\gb1\main.py, line
hello guys simple question that i seemed to be stumped on. I have something
Hello Guys! I started learning python GUI development. Let's say I have this script:
Hello guys i have been using JavaFx scene builder to build a gui that
Hello guys i have a problem streaming PDF files with php, i'm using this
Hello guys I'm creating an application that have a widget the application and the
Hello guys I have a DIV that I got passed trought a js function
Hello guys I have a little trouble with the my method [HTTPost], please see
Hello Guys I have msg box when i press on yes its close that
Hello guys i have a small problem at my console application i have a

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.