Array, set, generic parsing--"Freshman admission system"

Source: Internet
Author: User

first, concept (from the encyclopedia)

array: A variable of the same type is named with a name, and then the set of the variable is distinguished by the number, which is called the array name, and the number is called the subscript.

Collection : A collection is a combination of a variable number of data items (which can be 0) that may share certain characteristics and need to be manipulated in some way.

generic type: in program encoding, some types that contain parameters, that is, generic parameters can only represent classes and cannot represent individual objects.

  
Ii. History of Evolution


Begin mapping a value with a location in memory, using "variable" to use this value. Further developed, using a variable to refer to a set of values, the array was born. Later with the collection, it is a stronger array, dependent on the object class. The deposit collection is boxed, converted into an object class, pulled out and then disassembled into the previous type. When the element is large, it can cause performance degradation. Since we use the same type more conveniently, it later produces generics, which can convert the elements inside into specific types, reducing the trouble of unboxing.

Third, C # comparison

non-generic collection

TD valign= "Top" >

The C # collection contains

Name

Difference

System.Array

Array

The length is certain, cannot delete to change to investigate

system.collection

arraylist can be dynamically resized with added, removed features

  including ArrayList  bitarray  hastable  queue  stack  sortedlist.

All collections implement an interface IEnumerable

System.Collection.Generic

Generic collection

Equivalent to a collection that is not converted to an object.

Provides a higher type of safety and efficiency.

iv. application of generic set in university cloud platform


A small demo in the WCF layer of the freshman:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >///<summary>//Based on the college's number of students//</summary>//<param name= "FRESHDEP Artment "> Institute entity, Academy name </param>//<returns></returns> public list<freshstudentr Eportcontracts> Queryallfreshreport () {//Instantiate a generic collection of student report entity types LIST&LT;FRESHSTUDENTREPORTCONTR                        acts> liststudentreport = new list<freshstudentreportcontracts> ();            Instantiate B-Level student information freshstudententityservice en = new freshstudententityservice (); By invoking the B-tier method to implement the IList interface//To create an IList-based interface, list is to create an instance of the list Ilist<itoo. freshservice.model.freshstudententity> studentcollections = en. Loadenities ().                        ToList ();                       A method for defining B-tier query professional information Freshdepartmententiyservice queryalldepartments = new Freshdepartmententiyservice (); Call the B-tier method var listdepartment = Queryalldepartments.querydepartment (); Get all student entities//define a dorm entity FRESHDEP, take an entity attribute from Listdepartment to assign the value foreach (Freshdepartmententiy freshdep in L Istdepartment) {//define data contract freshstudentreportcontracts FSRC = new Freshstudentrepo                Rtcontracts (); Assigns the value of the entity to the data contract FSRC.                Departmentname = Freshdep.departmentname; The total number of students enrolled FSRC. Enterstudentnumber = Studentcollections.where (s = = S.freshdepartmentname = = freshdep.departmentname). ToList ().                Count (); The total number of students reported FSRC. Registerstudentnumber = Studentcollections.where (E = E.ischeckin = = 1 && e.freshdepartmentname = = Freshdep.departmentname). ToList ().                Count (); FSRC The total number of boys in the inquiry. Registerboysnumber = Studentcollections.where (E = E.ischeckin = = 1 && e.sex = 0 && e.freshdepartmentn Ame = = freshdep.departmentname). ToList ().            Count ();    The total number of female students reported FSRC. Registergrilsnumber = Studentcollections.where (E = E.ischeckin = = 1 && e.sex = 1 && e.freshdepartment Name = = freshdep.departmentname). ToList ().                               Count ();            The data contract value is added to the student report data Contract liststudentreport.add (FSRC); Return liststudentreport;//returns the data in the student report data contract}</span>

The generic collection, as I understand it, is that list<> is a set, and what is inside the angle brackets is the specified general type.

In this code, we first define a method:--queryallfreshreport the results of the query into list<freshstudentreportcontracts> based on the way the college queries the number of students in the college. This generic collection inside. The type specified by this generic is freshstudentreportcontracts.

In this collection, you can add the property values that contain fields (Departmentname,enterstudentnuber, etc.) in the data contract.

Before the machine room, the generic collection is stored in the entity. In a freshman project, not only can the model entity be stored, but it can also be a data contract entity, which is an improvement.


v. Summary

Whether it is a variable, an array, a collection, a generic is a container, can hold the data, but the "bottle" is not the same. From the holding of a data, the same type of multiple data, to different kinds of data, container development more humane, human object-oriented thinking is also constantly improving. Believe in the future when learning Java, the understanding of the container will be more in-depth.

  


Array, set, generic parsing--"Freshman admission system"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.