亲宝软件园·资讯

展开

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

宋勇野 人气:0
想了解C#实现基于链表的内存记事本实例的相关内容吗,宋勇野在本文为您仔细讲解C#基于链表的内存记事本的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:C#,链表,内存记事本,下面大家一起来学习吧。

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

加载全部内容

相关教程
猜你喜欢
用户评论