zoukankan      html  css  js  c++  java
  • C#学习笔记之——学生信息输入系统(Dictionary)

    创建一个学生类

    public class Student
    {
    	protected string name;
    	protected string stuID;
    	protected int score;
    	public Student(){
    	}
    	public string Name{
    		set{
    			if (name == null)
    				name = value;
    		}
    		get{
    			return name;
    		}
    	}
    	public string StuID{
    		set{
    			if (stuID == null)
    				stuID = value;
    		}
    		get{
    			return stuID;
    		}
    	}
    	public int Score{
    		set{
    			score = value;
    		}
    		get{
    			return score;
    		}
    	}
    }
    

    创建dictionary存放学生信息,录入完毕用学生学号排序

    Dictionary<int, Student> studentInfo = new Dictionary<int, Student> ();
    //Student stu = new Student ();
    Console.WriteLine ("please write down the student's information:(when write down " " (space) ,shut down)");
    Console.Write ("No.");
    int i;
    string a = Console.ReadLine ();
    while (a != " ") {
    				
    	Student stu = new Student ();
    	Console.Write ("student's name:");
    	stu.Name = Console.ReadLine ();
    	Console.Write ("student's ID:");
    	stu.StuID = Console.ReadLine ();
    	Console.Write ("student's score:");
    	stu.Score = int.Parse (Console.ReadLine ());
    	i = int.Parse (a);
    	studentInfo.Add (i, stu);
    	Console.Write ("No.");
    	a = Console.ReadLine ();
    }
    
    Dictionary<int, Student> studentIndo_SortedByValue = studentInfo.OrderBy(p=>p.Value.StuID).ToDictionary(p => p.Key, o => o.Value);
    foreach (var item in studentIndo_SortedByValue) {
    	Console.WriteLine (item.Key + " " + item.Value.Name + " " + item.Value.StuID + " " + item.Value.Score);
    }
    

    结果:

    please write down the student's information:(when write down " " (space) ,shut down)

    No.1

    student's name:Pink

    student's ID:03

    student's score:89

    No.2

    student's name:Sia

    student's ID:01

    student's score:67

    No.3

    student's name:Ed

    student's ID:02

    student's score:45

    No. 

    2 Sia 01 67

    3 Ed 02 45

    1 Pink 03 89


    黄老板的粉不要打我,我也是随便举的例子QAQ

  • 相关阅读:
    CF 561 div2 C
    CF #560 div3
    1.11 acm结束了,所以寒假学习Java基础
    11.5 cometoj #12 -- D XOR Pair (数位dp)
    11 .3 数位dp
    10.1 叉积 ,极角排序,扫描法求凸包
    9.11 状态矩阵 与 dp
    9.3 整理一下最短路算法
    9.3 欧拉定理 && 欧拉降幂 (扩展欧拉定理)&& 指数循环节
    Two Arithmetic Progressions (exgcd的一些注意事项
  • 原文地址:https://www.cnblogs.com/AlinaL/p/12852180.html
Copyright © 2011-2022 走看看