Search code examples
c#databaselinqmethodsconsole-application

Is it neccessary to create database for basic console app in c#?


here is my code,

Q#1- Is it neccessary to create database for basic console app in c#?

Q#2- I want to know that how do I create a AddEmployee method as well as other methods like RemoveEmployee & FindEmployee?

what I want is to give the user the choice between 1-3 to select and after that the console app shouldn't close and ask the user if they want to continue or not and upon pressing y from (y/n) the app should give choices again and exit upon pressing "n".

namespace UsingLinq

{

class Employee

{
    public int Id { get; set; }
    public string Name { get; set; }
    public string FatherName { get; set; }
}
class Program
{
    List<Employee> lstEmployees = new List<Employee>();

    static void Main()
    {
        while (true)
        {
            Console.WriteLine("1. Add Employee");
            Console.WriteLine("2. Remove Employee");
            Console.WriteLine("3. Find Employee");

            Console.WriteLine("Enter your choice: ");
            int selected = int.Parse(Console.ReadLine());

            switch (selected) {
                case 1:
                    AddEmployee();
                    break;
                case 2:
                    RemoveEmployee();
                    break;
                case 3:
                    FindEmployee();
                    break;
                default:
                    Console.WriteLine("invalid choice!");
                    break;

            }
        }
            
    }

    public static void AddEmployee()
    {

    }

    public static void RemoveEmployee()
    {

    }

    public static void FindEmployee()
    {

    }

}

}


Solution

  • No, it is not required to create a database for a small scale console application.

    Here's a rough completion of what you're looking for, albeit I'm assuming you want to be able to add father's name to the employee? Hopefully this gets you started in the right direction.

    https://dotnetfiddle.net/enQJjz