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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:38:48+00:00 2026-06-05T06:38:48+00:00

I’m trying to loop through a list (csv) containing two fields; a name and

  • 0

I’m trying to loop through a list (csv) containing two fields; a name and a date. There are various duplicated names and various dates in the list. I’m trying to deduce for each name in the list, where there are multiple instances of the same name, which corresponding date is the latest.

I realise, from looking at another answer, that I need to use the DateTime.Compare method which is fine, but my problem is working out which date is later. Once I know this I need to produce a file with unique names and the latest date relating to it.

This is my first question which makes me a newbie.

EDIT:

Initially I thought it would be ‘ok’ to set the LatestDate object to a date that wouldn’t show up in my file, therefore making any later dates in the file the LatestDate.

Here’s my coding so far:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace flybe_overwriter
{
class Program
{
    static DateTime currentDate;
    static DateTime latestDate = new DateTime(1000,1,1);
    static HashSet<string> uniqueNames = new HashSet<string>();

    static string indexpath = @"e:\flybe test\indexing.csv";
    static string[] indexlist = File.ReadAllLines(indexpath);
    static StreamWriter outputfile = new StreamWriter(@"e:\flybe test\match.csv");

    static void Main(string[] args)
    {

        foreach (string entry in indexlist)
        {

            uniqueNames.Add(entry.Split(',')[0]);

        }

        HashSet<string>.Enumerator fenum = new HashSet<string>.Enumerator();
        fenum = uniqueNames.GetEnumerator();

        while (fenum.MoveNext())
        {
            string currentName = fenum.Current;


            foreach (string line in indexlist)
            {
                currentDate = new DateTime(Convert.ToInt32(line.Split(',')[1].Substring(4, 4)), 
                                           Convert.ToInt32(line.Split(',')[1].Substring(2, 2)), 
                                           Convert.ToInt32(line.Split(',')[1].Substring(0, 2)));

                if (currentName == line.Split(',')[0])
                { 
                    if(DateTime.Compare(latestDate.Date, currentDate.Date) < 1)
                    {
                      //  Console.WriteLine(currentName + " " + latestDate.ToShortDateString() + " is earlier than " + currentDate.ToShortDateString());
                    }
                    else if (DateTime.Compare(latestDate.Date, currentDate.Date) > 1)
                    {
                     //   Console.WriteLine(currentName + " " + latestDate.ToShortDateString() + " is later than " + currentDate.ToShortDateString());
                    }
                    else if (DateTime.Compare(latestDate.Date, currentDate.Date) == 0)
                    {
                     // Console.WriteLine(currentName + " " + latestDate.ToShortDateString() + " is the same as " + currentDate.ToShortDateString());
                    }

                }
            }

        }


    }
}

}

Any help appreciated.
Thanks.

  • 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-05T06:38:50+00:00Added an answer on June 5, 2026 at 6:38 am

    all in one, use the Max() function on your Datetimes instead making your own test.

    var result = indexList
            //"transform" your initial list of strings into an IEnumerable of splitted strings (string[])
            .Select(list => list.Split(','))
            //in this new List of string[], select the first part in text, select and Convert the second part in DateTime. 
            //We now have an IEnumerable of anonymous objects, composed of a string and a DateTime Property
            .Select(splittedList => new
                                        {
                                            text = splittedList[0],
                                            date = new DateTime(Convert.ToInt32(splittedList[1].Substring(4, 4)),
                                                                Convert.ToInt32(splittedList[1].Substring(2, 2)),
                                                                Convert.ToInt32(splittedList[1].Substring(0, 2)))
                                        })
            //group that new List by the text Property (one "entry" for each distinct "text"). 
            //GroupBy creates an IGrouping<out TKey, out TElement>, kind of special dictionary, with an IEnumerable<TResult> as "value" part 
            //(here an IEnumerable of our anonymous object)
            .GroupBy(textDateTimeList => textDateTimeList.text)
             //from this grouping, take the "key" (which is the "distinct text", and in the IEnumerable<anonymousObject>, take the Max Date. 
             //We now have a new List of anonymous object, with a string Property and a DateTime Property
            .Select(group => new
                                 {
                                     stringField = group.Key,
                                     maxDateField = group.Max(dateField => dateField.date)
                                 });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.