C Implementation of Memory Notepad Based on Linked List

  • 2021-07-13 06:05:26
  • OfStack

In this paper, an example is given to describe the implementation of memory notepad based on linked list by C #. Share it for your reference. The details are as follows:

User model:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
 public class User
 {
  private string username;
  public string Username
  {
   get { return username; }
   set { username = value; }
  }
  private string sex;
  public string Sex
  {
   get { return sex; }
   set { sex = value; }
  }
  private string age;
  public string Age
  {
   get { return age; }
   set { age = value; }
  }
  private string phone;
  public string Phone
  {
   get { return phone; }
   set { phone = value; }
  }
 }
}

The soul of the program Controller:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
 public class Controller
 {
  private ArrayList a = new ArrayList();
  public ArrayList A
  {
   get { return a; }
   set { a = value; }
  }
  public void add(User user) 
  {
   A.Add(user);
  }
  public void delete(User user) 
  {
   if (A.Contains(user))
   {
    A.Remove(user);
   }
   else
   {
    Console.WriteLine(" User does not exist! ");
   }
  }
  public ArrayList select(ArrayList a) 
  {
   return a;
  }
  public User search(string username)
  {
   foreach(User user in A)
   {
    if (user.Username == username)
    {
     return user;
    }
   }
   return null;
  }
 }
}

Program.cs:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
 class Program
 {
  static void Main(string[] args)
  {
   Controller controller = new Controller();
   while (true)
   {
    Console.WriteLine(" Please enter your action: ");
    Console.WriteLine("1, Add users ");
    Console.WriteLine("2, Delete user ");
    Console.WriteLine("3, Browse user ");
    Console.WriteLine("4, Quit ");
    string input = Console.ReadLine();
    if(input=="1")
    {
     User user = new User();
     Console.WriteLine(" User name: ");
     user.Username = Console.ReadLine();
     Console.WriteLine(" User last name: ");
     user.Sex = Console.ReadLine();
     Console.WriteLine(" User age: ");
     user.Age = Console.ReadLine();
     Console.WriteLine(" Telephone number: ");
     user.Phone = Console.ReadLine();
     controller.add(user);
    }
    if(input=="2")
    {
     Console.WriteLine(" Please enter a user name ");
     string username = Console.ReadLine();
     if (controller.search(username)!=null)
     {
      User user = controller.search(username);
      controller.delete(user);
     }
     else
     {
      Console.WriteLine(" This user does not exist! ");
     }
    }
    if(input=="3")
    {
     foreach(User user in controller.A )
     {
      Console.WriteLine(user.Username);
     }
    }
   }
  }
 }
}

I hope this article is helpful to everyone's C # programming.


Related articles: