C#完成基於鏈表的內存記事本實例。本站提示廣大學習愛好者:(C#完成基於鏈表的內存記事本實例)文章只能為提供參考,不一定能成為您想要的結果。以下是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#法式設計有所贊助。