uj5u.com熱心網友回復:
這就是定義一個類,還有什么難的……uj5u.com熱心網友回復:
class Account{
public string [] AccountNumber { get; set; }
public string Name { get; set; }
public string ID { get; set; }
public double Balance { get; set; }
public void Deposit()
{
}
public void Draw()
{
}
public void Transfer()
{
}
}
————————————————————————————————————
static void Main(string[] args)
{
Account a = new Account();
string[] s_arry ={ "Account112233001" ,"Account112233002", "Account112233003" };
a.AccountNumber = s_arry;
foreach (string str in a.AccountNumber)
{
Console.WriteLine(str);
}
int result = a.AccountNumber.Length;
Console.WriteLine("共有"+result+"個賬戶");
}
——————————————————————————————
uj5u.com熱心網友回復:
非常感謝,謝謝謝謝謝謝
uj5u.com熱心網友回復:
提幾個小問題,第一 ID應該時 uint比較好, Balance 用decimal,精度較好第二,AccountNumber 應該時 static 的,用戶應該時銀行的屬性,而不是實體的,在Account的 new 方法里做增加
uj5u.com熱心網友回復:
using System;using System.Collections.Generic;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
Account a = new Account("張三");
Account b = new Account("李四");
Account c = new Account("王五");
Console.WriteLine("共有" + Account.AccountNumber + "個賬戶");
Console.WriteLine("分別為:");
foreach (string item in Account.AccountNames)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
}
class Account
{
private static uint id = 100000000;//ID 自動分配,設定起始ID,每增加一個賬戶,ID加1
private static int accountNumber = 0;
public static int AccountNumber
{ get => accountNumber; }
private static List<string> accountNames=new List<string> ();
public static List<string> AccountNames { get => accountNames; }
public string Name { get; set; }
public uint ID { get; set; }
public double Balance { get; set; }
public Account(string name)
{
Name = name;
accountNumber++;//銀行總賬戶人數加1
ID = id++;//分配ID
accountNames.Add(name);
}
public void Deposit( decimal num)
{
}
public void Draw(decimal num)
{
}
public void Transfer(decimal num)
{
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/68111.html
標籤:C#
