首页 新闻 会员 周边

C#中,是设计链表来保存数据吗?

0
悬赏园豆:30 [已解决问题] 解决于 2008-10-14 09:00

有一个银行类,我是这么建立的:
using System;

public class Bank
{
    #region 私有成员
 protected int Account;
 protected String userName;
 protected String openAccount;
 protected String identityCard;
 protected float balance;
    #endregion

    public Bank()
    { }

    public Bank(int Account, String userName, String openAccount,
                    String identityCard, float balance)
    {
        set(Account, userName, openAccount,
                                   identityCard, balance);
      
 }

    public void set(int Account, String userName, String openAccount,
                     String identityCard, float balance)
    {
        this.Account = Account;
        this.userName = userName;
        this.openAccount = openAccount;
        this.identityCard = identityCard;
        this.balance = balance;
    }


    public void set(float balance)
    {
        this.balance = balance;
    }

    public void set(Bank newAccount)
    {
        this.set(newAccount.Account, newAccount.userName,
                newAccount.openAccount, newAccount.identityCard,
                newAccount.balance);
    }

    public void saving(float money)
    {
        set(this.balance + money);
    }

 

    public void fetching(float money)
    {
     if(balance>=money)
     {
      set(this.balance-money);
         Console.WriteLine("操作成功");
     }
     else
     {
       Console.WriteLine("您的余额不够");
      
      }
     }

    public void Print()
   {
     Console.WriteLine("帐户:"+this.Account+"姓名:"+this.userName+"余额:"+this.balance);
    }

 

但是我想操作时保存这些信息,在数据结构课程中,我是用链表实现的。
问题是:我有必要设计一个链表来保存这些信息吗?还是有更好的办法?

问题补充: 我可能没把需求写清楚 using System; public class test { static void Main(String[] args) { Console.WriteLine("请选择一项操作:"); Console.WriteLine("1-----新建帐户."); Console.WriteLine("2-----查找帐户."); string operation; operation = Console.ReadLine(); order operationOrder; operationOrder = (order)Enum.Parse(typeof(order), operation); switch (operationOrder) { case order.NewAccount: Bank bank1 = new Bank(); Console.WriteLine("请输入姓名:"); string name = Console.ReadLine(); Console.WriteLine("请输入身份证号码:"); string identityCard = Console.ReadLine(); //。。。。 break; case order.FindAccount: Console.WriteLine("待开发"); break; default: Console.WriteLine("输入有误"); break; } Console.ReadLine(); } 我想做的是,循环建新建帐户时(代码还没写),能够保存数据。问用链表这个思路是否正确,或者不需要链表,有更好的思路。谢谢!
idoku的主页 idoku | 菜鸟二级 | 园豆:267
提问于:2008-10-13 07:02
< >
分享
最佳答案
0

链表结构是为了可以快速的增删节点,存储结构可以考虑采用顺序存储,或者用数据库,xml这类的方式存储,用链表方式存储感觉比较复杂,而且没有太大的必要。

eaglet | 专家六级 |园豆:17139 | 2008-10-13 08:49
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册