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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:25:34+00:00 2026-06-14T23:25:34+00:00

List<Int32> dansConList = new List<Int32>(); dansConList[0] = 1; dansConList[1] = 2; dansConList[2] = 3;

  • 0
List<Int32> dansConList = new List<Int32>();
dansConList[0] = 1;
dansConList[1] = 2;
dansConList[2] = 3;

List<Int32> dansRandomList = new List<Int32>();
dansRandomList[0] = 1;
dansRandomList[1] = 2;
dansRandomList[2] = 4;

I need a method that, when evaluating the above lists, will return false for dansRandomList and true for dansConList based on the fact dansConList has a consecutive number sequence in it’s values, and dansRandomList does not (missing the value 3).

Using LINQ is preferable, if possible.

What I’ve Tried:

  • For the sake of achieving the end result, I have used a for loop and compare with ‘i’ (loop counter) to evaluate the values, but as mentioned above I’d like to use LINQ for this.
  • 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-14T23:25:35+00:00Added an answer on June 14, 2026 at 11:25 pm

    One-liner, only iterates until the first non-consecutive element:

    bool isConsecutive = !myIntList.Select((i,j) => i-j).Distinct().Skip(1).Any();
    

    Update: a couple examples of how this works:

    Input is { 5, 6, 7, 8 }
    Select yields { (5-0=)5, (6-1=)5, (7-2=)5, (8-3=)5 }
    Distinct yields { 5, (5 not distinct, 5 not distinct, 5 not distinct) }
    Skip yields { (5 skipped, nothing left) }
    Any returns false
    
    Input is { 1, 2, 6, 7 }
    Select yields { (1-0=)1, (2-1=)1, (6-2=)4, (7-3=)4 } *
    Distinct yields { 1, (1 not distinct,) 4, (4 not distinct) } *
    Skip yields { (1 skipped,) 4 }
    Any returns true
    

    * The Select will not yield the second 4 and the Distinct will not check it, as the Any will stop after finding the first 4.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Single and multiple lists Consider the following lists: List<Int32> appleIdentities = new List<int>(new[] {
I need something similar to List<String, Int32, Int32> . List only supports one type
I need to use a list pulled from sql, list is built from Dictionary<Int32,
I have some interface and class that contain List public interface IListContain { Int32
I have a list of query statements that need to be posted back to
How are the Indexers are defined in List and Arrays. List<MyStruct> lists=new List<MyStruct>(); where
I have the following method that calculates the top 20 numbers in a list
public List<CompanyRatingInfo> GetTopCompanies() { return objectContext.Companies.OrderBy(c => c.Reviews.Sum(r => r.Rating)) .Select(co => new CompanyRatingInfo()
I have the following method: public List<Alert> GetMonthlyAlertsByAccountID(Int32 AccountID, params int[] alertTypes) { List<Alert>
Here is a list of blittable types . It contains Int32 and Int64. But

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.