namespace fengzhuang { class Class2 { private string _Name; private string _Code; public string _Sex; public Class2()//構造函數 { _Sex = "男";//每次初始化都會默認_Sex的值為“男” Console.WriteLine("構造函數"); } public string nv()//函數 { _Sex = "女"; return _Sex; } } }
static void Main(string[] args) { Class2 op=new Class2();//本身就存在的,只要初始化一下類,便會調用函數, Console.WriteLine(op._Sex); op.nv();//調用函數, 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 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> /// 接收arraylist,排序後,返回arraylist /// </summary> /// <param name="arr">存放了student類對象的arraylist</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; } } }