//************************************************************
//
// Dictionary示例代码
//
// Author:三五月儿
//
// Date:2014/09/14
//
//
//************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
namespace DictionaryExp
{
class Program
{
static void Main(string[] args)
{
//所有班级所有学生成绩报告单
Dictionary<int, List<ScoreReport>> scoreDictionary = new Dictionary<int, List<ScoreReport>>();
//将1班所有学生成绩加入字典
scoreDictionary.Add(1,
new List<ScoreReport>()
{
new ScoreReport(){Name="三五月儿",ChineseScore=100,MathScore=100,EnglishScore=100},
new ScoreReport(){Name="张三",ChineseScore=80,MathScore=78,EnglishScore=91},
new ScoreReport(){Name="李四",ChineseScore=90,MathScore=87,EnglishScore=88}
});
//将2班所有学生的成绩加入字典
scoreDictionary.Add(2,
new List<ScoreReport>()
{
new ScoreReport(){Name="王五",ChineseScore=78,MathScore=88,EnglishScore=98},
new ScoreReport(){Name="丁六",ChineseScore=77,MathScore=99,EnglishScore=91},
new ScoreReport(){Name="魏源",ChineseScore=45,MathScore=66,EnglishScore=99}
});
//将3班所有学生的成绩加入字典
scoreDictionary.Add(3,
new List<ScoreReport>()
{
new ScoreReport(){Name="周鹏",ChineseScore=99,MathScore=89,EnglishScore=78},
new ScoreReport(){Name="毛钱",ChineseScore=66,MathScore=98,EnglishScore=91},
new ScoreReport(){Name="皮蛋",ChineseScore=87,MathScore=69,EnglishScore=88}
});
//所有班级学生成绩统计报告单
Dictionary<int, ScoreStatistics> scoreStatisticsDictionary = new Dictionary<int, ScoreStatistics>();
scoreStatisticsDictionary.Add(1, new ScoreStatistics());
scoreStatisticsDictionary.Add(2, new ScoreStatistics());
scoreStatisticsDictionary.Add(3, new ScoreStatistics());
//获取班级Key的集合
Dictionary<int, List<ScoreReport>>.KeyCollection keyCollection = scoreDictionary.Keys;
//通过班级Key遍历班级学生成绩
foreach (var key in keyCollection)
{
//班级成绩统计报告单中包含本班级时才继续
if (scoreStatisticsDictionary.ContainsKey(key))
{
//当前班级所有学生的详细成绩报告单
List<ScoreReport> scoreList = new List<ScoreReport>();
scoreDictionary.TryGetValue(key, out scoreList);
if (scoreList != null && scoreList.Count > 0)
{//当前班级所有学生的详细成绩报告单中存在数据
int count = scoreList.Count;//当前班级学生人数
//生成当前班级学生成绩的统计报告单
ScoreStatistics scoreStatistics = new ScoreStatistics();
scoreStatisticsDictionary.TryGetValue(key, out scoreStatistics);
scoreStatistics.ClassId = key;
scoreStatistics.TotalChineseScore = scoreList.Sum(it => it.ChineseScore);
scoreStatistics.TotalMathScore = scoreList.Sum(it => it.MathScore);
scoreStatistics.TotalEnglishScore = scoreList.Sum(it => it.EnglishScore);
scoreStatistics.AverageChineseScore = scoreStatistics.TotalChineseScore / count;
scoreStatistics.AverageMathScore = scoreStatistics.TotalMathScore / count;
scoreStatistics.AverageEnglishScore = scoreStatistics.TotalEnglishScore / count;
}
}
}
foreach (var s in scoreStatisticsDictionary)
{
Console.WriteLine("ClassId = {0},TotalChineseScore = {1},TotalMathScore = {2},TotalEnglishScore = {3},AverageChineseScore = {4},AverageMathScore = {5},AverageEnglishScore = {6}",
s.Value.ClassId, s.Value.TotalChineseScore, s.Value.TotalMathScore, s.Value.TotalEnglishScore, s.Value.AverageChineseScore, s.Value.AverageMathScore, s.Value.AverageEnglishScore);
Console.WriteLine("-------------------------------------------------");
}
}
}
class ScoreReport
{
public string Name { get; set; }
public int ChineseScore { get; set; }
public int MathScore { get; set; }
public int EnglishScore { get; set; }
}
class ScoreStatistics
{
public int ClassId { get; set; }
public int TotalChineseScore { get; set; }
public int TotalMathScore { get; set; }
public int TotalEnglishScore { get; set; }
public int AverageChineseScore { get; set; }
public int AverageMathScore { get; set; }
public int AverageEnglishScore { get; set; }
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有