欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2023-12-11 20:35:23
本文实例讲述了c#实现基于链表的内存记事本。分享给大家供大家参考。具体如下: user模型: using system; using system.colle...

本文实例讲述了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#程序设计有所帮助。

上一篇:

下一篇: