I created a text file using following method:

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

namespace FajlliTekstual
    class Program
        static void Main(string[] args)
            FileStream fileStream = new FileStream("shenime.txt", FileMode.Create, FileAccess.Write);
            TextWriter writer = new StreamWriter(fileStream);
            Console.WriteLine("Someone Else");
            writer.WriteLine("Bla Bla");
            writer.WriteLine("Bla Bla");
            writer.WriteLine("Unkown Person");

**/Now the text file holds the first and last name of someone.
My goal is to read this text file and to show the results in a console application sorted name like those that begin with A or B or other letter.
This first name latter should be given by the user and then the list must be shown.
Thank you in advance for your reply.

I don't find what your trying to do clear. Nor is the example data any good. Do Bla Bla count as an individual? or information relating to Someone else? Please consider re-doing the explanation with clarified requirements.

Ok the BLA BLA and Someone else are the first and last names of someone. It means that in a text file I created is a list of First and Last names. All i want to know is how to create a method to sort the list with those names that begin with a specific letter for example with letter D. The result should be shown in console application.
Hopefully you got the point of my goal.

Edited 4 Years Ago by dr_iton

So say I had this as my list

Steve A
Steve B
John C
Scott A
Dani T

and wanted the letter S, your output should be:

Scott A
Steve A
Steve B


One possible solution....

string[] sortit = File.ReadAllLines("shenime.txt");
foreach (string str in sortit) Console.WriteLine(str); 
            List<string> Names = new List<string>();
            List<string> SortedRefinedNames = new List<string>();
            StreamReader sr = new StreamReader(@"C:\Users\maskew\Desktop\Names.txt");
            string NameEntry;
            while ((NameEntry = sr.ReadLine()) != null)

            Console.Write("First letter of name to search: ");
            string Letter = Console.ReadLine();

            foreach (string Name in Names)
                if (Name.Substring(0, 1).ToUpper() == Letter.ToUpper())



            foreach (string Name in SortedRefinedNames)


Edited 4 Years Ago by Mike Askew

This question has already been answered. Start a new discussion instead.