20141211--C # constructor,

Source: Internet
Author: User

20141211--C # constructor,

Namespace fengzhuang {class Class2 {private string _ Name; private string _ Code; public string _ Sex; public Class2 () // constructor {_ Sex = "male "; // The default value of _ Sex is "male" Console every initialization. writeLine ("constructor");} public string nv () // function {_ Sex = "female"; return _ Sex ;}}}

 

Static void Main (string [] args) {Class2 op = new Class2 (); // It exists. You only need to initialize the class and call the function, Console. writeLine (op. _ Sex); op. nv (); // call the function, Console. writeLine (op. _ Sex); Console. writeLine (); Console. readLine ();}
Using System; using System. collections; using System. collections. generic; using System. linq; using System. text; namespace xueshengxuanke {class Program {static void Main (string [] args) {Console. writeLine ("Enter the number of students:"); int n = int. parse (Console. readLine (); Console. writeLine ("Enter student ID, name, score"); ArrayList arr = new ArrayList (); for (int I = 0; I <n; I ++) {student s = new student (); Console. write ("student ID:"); s. code = int. parse (Console. readLine (); Console. write ("name:"); s. name = Console. readLine (); Console. write ("score:"); s. score = decimal. parse (Console. readLine (); arr. add (s) ;}decimal sum = 0; for (int I = 0; I <n; I ++) {student avgs = (student) arr [I]; sum + = avgs. score;} ArrayList newarr = new student (). maopao (arr); student ss1 = (student) newarr [0]; Console. writeLine ("Name: {0} highest score: {1}", ss1.Name, ss1.Score); int x = n-1; student ss2 = (student) newarr [x]; console. writeLine ("Name: {0} segmentation: {1}", ss2.Name, ss2.Score); Console. writeLine ("average score: {0}", sum/n); for (int I = 0; I <n; I ++) {student avgs = (student) newarr [I]; Console. writeLine ("student ranking: * ********************************* "); Console. writeLine ("student ID name score ranking"); Console. writeLine ("{0} {1} {2} {3}", avgs. code, avgs. name, avgs. score, I + 1);} Console. readLine ();}}}

 

Using System; using System. collections; using System. collections. generic; using System. linq; using System. text; namespace xueshengxuanke {class student {private int _ Code; public int Code {get {return _ Code;} set {_ Code = value ;}} private string _ Name; public string Name {get {return _ Name;} set {_ Name = value;} private decimal _ Score; public decimal Score {get {return _ Score ;} set {_ Score = value ;}/// <summary> // receives the arraylist. After sorting, return arraylist /// </summary> /// <param name = "arr"> arraylist of student class objects </param> /// <returns> </returns> public ArrayList Maopao (ArrayList arr) {int n = arr. count; for (int I = 0; I <n; I ++) {for (int j = I; j <n; j ++) {student s1 = (student) arr [I]; student s2 = (student) arr [j]; if (s1.Score <s2.Score) {student zhong = new student (); zhong = s1; arr [I] = s2; arr [j] = zhong ;}}return arr ;}}}

Related Article

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.