Compare user input with each line in text file

Trianne

New member
Joined
Aug 7, 2018
Messages
2
Programming Experience
Beginner
Hi,

I have a code that append a user input name to the end of list.
I like to know how I can check to see if user input matches with the name in file
if so print "name exists" if not print "name added to list"

Thank you for your time.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

namespace ChatBot
{
   class Program
   {
      static void Main(string[] args)
     {
         string filePath = @"C:\C#\Projects\names.txt";

         List<string> lines = File.ReadAllLines(filePath).ToList();

         Console.Write("Please enter your full name? ");
         string FullName = Console.ReadLine();

         // append and write FullName to file
         lines.Add(FullName);
         File.WriteAllLines(filePath, lines);

         //displays result
         Process.Start(filePath);

      }
   }
}


PS - How do I provide my code with proper spacing?
 
Back
Top Bottom