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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:01:43+00:00 2026-06-15T23:01:43+00:00

I am currently using a normal looping to check if the list of numbers

  • 0

I am currently using a normal looping to check if the list of numbers are in order.

I am currently learning LINQ and I want to know how can I implement in LINQ to check if the sequence of numbers are in correct order.

For example I have this list of sequence number:

1.0
1.1
1.2
1.4
2.0

The program needs to flag as error the line 1.4 because 1.3 is missing.

How can I achieve that using LINQ?

Thanks for all your help. 🙂

It’s like table of contents:

1.1 followed by 1.3 is invalid, 1 followed by 2 is valid. 1.4 followed by 2 is valid.

Here’s the code that I am using it still has a lot of lapses I think:

using (System.IO.StreamReader reader = new System.IO.StreamReader("D:\\test.txt"))
{
    double prevNumber = 0;

    while (reader.Peek() >= 0)
    {
        double curNumber = double.Parse(reader.ReadLine());
        double x = Math.Round(curNumber - prevNumber, 1);

        if (x == 0.1)
        {
            prevNumber = curNumber;
        }

        else
        {
            int prev = (int)Math.Floor(prevNumber);
            int cur = (int)Math.Floor(curNumber);

            if ((cur - prev) == 1)
            {
                prevNumber = curNumber;
            }
            else
            {
                //error found
            }
        }
    }
}
  • 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-15T23:01:44+00:00Added an answer on June 15, 2026 at 11:01 pm

    This method takes a filename and returns an array of line numbers of incorrect versions. For your example it returns { 4 }.

    It only handles numbers of the form x.y, as that appears to be all you want it to handle.

    static int[] IncorrectLines(string filename)
    {
        // Parse the file into an array of ints, 10* each version number.
        var ints =  File.ReadLines(filename)
            .Select(s => (int)(10 * decimal.Parse(s))).ToArray();
        // Pair each number up with the previous one.
        var pairs = ints
            .Zip(ints.Skip(1), (p, c) => new { Current = c, Previous = p });
        // Include the line numbers
        var withLineNos = pairs
            .Select((pair, index) => new { Pair = pair, LineNo = index + 2 });
        // Only keep incorrect lines
        var incorrect = withLineNos.Where(o => ! (         // not one of either:
                o.Pair.Current - 1 == o.Pair.Previous ||   // simple increment
                (o.Pair.Current % 10 == 0 &&               // major increment
                 (o.Pair.Current / 10) - 1 == o.Pair.Previous / 10)
            ));
        return incorrect.Select(o => o.LineNo).ToArray();
    }
    

    Honestly? I think you’re better off with a loop.

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

Sidebar

Related Questions

I am currently using Eclipse Version: 3.5.1 . It works perfectly in normal conditions,
I'm currently using a VBO for the texture coordinates, normals and the vertices of
Currently using the HTTPServletRequest class and specifically the .getQueryString method to retrieve an inputted
Currently using Google Analytics as a supplement to our paid tracking software, but neither
Currently using MySQL version 5.1.6 This is my first real world build and so
Currently using Xcode 4.2 and I have two view controllers (1 and 2). I
I currently using android NDK to write some native code in C. I have
I'm currently using the NEST ElasticSearch C# Library for interacting with ElasticSearch. My project
I'm currently using inline javascript to clear an input text's default value on focus.
I am currently using Ubuntu 11.10 and java SE 1.6.0_26. I am trying to

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.