C#实现基于链表的内存记事本实例

Alexandra ·
更新时间:2024-11-13
· 848 次阅读

本文实例讲述了C#实现基于链表的内存记事本。分享给大家供大家参考。具体如下:

User模型:

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; } } } }

程序的灵魂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("用户不存在!"); } } 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("请输入您的操作:"); Console.WriteLine("1,增加用户"); Console.WriteLine("2,删除用户"); Console.WriteLine("3,浏览用户"); Console.WriteLine("4,退出"); string input = Console.ReadLine(); if(input=="1") { User user = new User(); Console.WriteLine("用户姓名:"); user.Username = Console.ReadLine(); Console.WriteLine("用户姓别:"); user.Sex = Console.ReadLine(); Console.WriteLine("用户年龄:"); user.Age = Console.ReadLine(); Console.WriteLine("电话号码:"); user.Phone = Console.ReadLine(); controller.add(user); } if(input=="2") { Console.WriteLine("请输入用户姓名"); string username = Console.ReadLine(); if (controller.search(username)!=null) { User user = controller.search(username); controller.delete(user); } else { Console.WriteLine("该用户不存在!"); } } if(input=="3") { foreach(User user in controller.A ) { Console.WriteLine(user.Username); } } } } } }

希望本文所述对大家的C#程序设计有所帮助。

您可能感兴趣的文章:C#实现记事本查找与替换功能C#用记事本编写简单WinForm窗体程序C#编写一个简单记事本功能C#逐行分元素读取记事本数据并写入数据库的方法C#实现将记事本中的代码编译成可执行文件的方法C#实现简单记事本程序



C# 记事本 链表

需要 登录 后方可回复, 如果你还没有账号请 注册新账号