日期:2014-05-18 浏览次数:20975 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace AAA
{
class Program
{
static void Main(string[] args)
{
List<user> list = new List<user>();
list.Add(new user() { struserNo = "A1", struserName = "張三", deposit = 10000, dtUser = null });
list.Add(new user() { struserNo = "A1", struserName = "張三", deposit = 20000, dtUser = null });
list.Add(new user() { struserNo = "A1", struserName = "張三1", deposit = 20000, dtUser = null });
list.Add(new user() { struserNo = "A1", struserName = "張三2", deposit = 20000, dtUser = null });
list.Add(new user() { struserNo = "A1", struserName = "張三3", deposit = 20000, dtUser = null });
list.Add(new user() { struserNo = "A2", struserName = "李四", deposit = 30000, dtUser = null });
list.Add(new user() { struserNo = "A2", struserName = "李四", deposit = 40000, dtUser = null });
list.Add(new user() { struserNo = "A2", struserName = "李四1", deposit = 40000, dtUser = null });
list.Add(new user() { struserNo = "A2", struserName = "李四2", deposit = 40000, dtUser = null });
list.Add(new user() { struserNo = "A2", struserName = "李四3", deposit = 40000, dtUser = null });
list.Add(new user() { struserNo = "A3", struserName = "王五", deposit = 44000, dtUser = null });
user u = null;
double total = 0;
String struserName = "";
for (int i = 0; i < list.Count(); i++)
{
u = list[i];
//1:取出所有存款帳號(struserNo)为“A1”的存款金額(deposit)之和
if (u.struserNo.Equals("A1"))
{
total += u.deposit;
}
//2:取出存款金額(deposit)为“40000”并且存款帳號(struserNo)为“A2”的存款名(struserName)
if (u.struserNo.Equals("A2") && (u.deposit == 40000))