nlanka 0 Newbie Poster
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace Cities
{
    class Hometown
    {



        public string City { get; set; }
        public string State { get; set; }

         public Hometown(string City, string State )
        {
            this.City = City;
            this.State = State;
        }

         public Hometown()
         {

         }


    }

    class Program
    {


            static void Main(string[] args)
        {
            int counter = 0;
            string line;
            string  cities = "";
            string  states = "";

            List<Hometown> hometown = new List<Hometown> { new Hometown { }};
            int numStates = 0; 







            System.IO.StreamReader file =
   new System.IO.StreamReader("cities.txt");
            while ((line = file.ReadLine()) != null)
            {

                 counter++;


                string[] towninfo = line.Split(',');

                    cities = towninfo[0];// String on the left of the comma
                    states = towninfo[1]; // String on the right of the comma
                    hometown.Add(new Hometown(cities, states));



            }
                Console.WriteLine(counter);







            file.Close();






            var orderedHometowns = from h in hometown
                                   orderby h.City ascending
                                   select h;
            foreach (Hometown hometowns in orderedHometowns)
            {
                Console.WriteLine(hometowns.City);
            }
                var  cityQuery =
                            from h in hometown
                            from s in h.State
                            from c in s.City
                           where s.Equals(Console.ReadLine())

                foreach (var cs in cityQuery)
                {
                    Console.WriteLine(cs.City);


                }


            Console.ReadLine();

        }
    }
}

Here is what I need to do

Execute a Linq query to count how many records are in the list and present the total to the end user.

Execute a Linq query to sort the entries in the list in ascending order and present the list of cities to the end user, in order.
Execute a Linq query to find all states starting with a specific letter. Prompt the user for the letter they want to look for, then present those that start with that letter to them. There is no need at this time to validate that they entered a letter.
Execute a Linq query to find all states that are from a given state. Prompt the user for the state they want to look for, then present those that are from that state to them. Again there is no need to validate that they entered a valid state.

here is what I have in the text file

Chicago,IL
Bridgewater,NJ
Flemington,NJ
Manhattan,NY
NewYork City,NY

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.