using System.Collections.Generic;
public static List<Bet> Bets = new List<Bet>();
public static void Main()
Bets.Add(new Bet { BillNo = "N190501001", BetAmount = 10, WinLoss = 12 });
Bets.Add(new Bet { BillNo = "N190501002", BetAmount = 10, WinLoss = 0 });
CounterWithBetAmount counterWithBetAmount = new CounterWithBetAmount(Bets);
CounterWithoutBetAmount counterWithoutBetAmount = new CounterWithoutBetAmount(Bets);
Console.WriteLine("包含本金的加總:" + counterWithBetAmount.Calculate()+"\n"+ "不包含本金的加總:" + counterWithoutBetAmount.Calculate());
public string BillNo {set;get;}
public decimal BetAmount {set;get;}
public decimal WinLoss {set;get;}
public interface CalculateInterface
public class CounterWithBetAmount:CalculateInterface
private decimal _counterwithbetAmount;
public CounterWithBetAmount(List<Bet> bets)
_counterwithbetAmount = 0;
public decimal Calculate()
foreach (var item in _bets)
_betamount += item.BetAmount;
_winloss += item.WinLoss;
_counterwithbetAmount = _betamount + _winloss;
return _counterwithbetAmount;
public class CounterWithoutBetAmount:CalculateInterface
private decimal _counterwithoutbetAmount;
public CounterWithoutBetAmount(List<Bet> bets)
_counterwithoutbetAmount = 0;
public decimal Calculate()
foreach (var item in _bets)
_winloss += item.WinLoss;