国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

20141211--C# 構造函數

2019-11-17 02:42:56
字體:
來源:轉載
供稿:網友

20141211--C# 構造函數

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();        }
image

 

習題:

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("請輸入學生人數:");            int n = int.Parse(Console.ReadLine());            Console.WriteLine("請輸入學生學號、姓名、分數");            ArrayList arr = new ArrayList();            for (int i = 0; i < n; i++)            {                student s = new student();                Console.Write("學號:");                s.Code = int.Parse(Console.ReadLine());                Console.Write("姓名:");                s.Name = Console.ReadLine();                Console.Write("分數:");                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("姓名:{0}最高分為:{1}", ss1.Name, ss1.Score);            int x = n - 1;            student ss2 = (student)newarr[x];            Console.WriteLine("姓名:{0}最低分為:{1}", ss2.Name, ss2.Score);            Console.WriteLine("平均分:{0}", sum / n);            for (int i = 0; i < n; i++)            {                student avgs = (student)newarr[i];                Console.WriteLine("學生名次為:***********************************");                Console.WriteLine("學號         姓名           分數                 名次");                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>        /// 接收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;        }    }}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 留坝县| 湛江市| 毕节市| 固原市| 麦盖提县| 桦川县| 图木舒克市| 富宁县| 榆社县| 郎溪县| 上犹县| 樟树市| 穆棱市| 伊金霍洛旗| 广宁县| 南漳县| 霍邱县| 榕江县| 临沂市| 姜堰市| 井研县| 鄂托克前旗| 台南市| 霞浦县| 横山县| 芜湖市| 澄江县| 璧山县| 临泽县| 桦南县| 晴隆县| 上思县| 德阳市| 乐昌市| 高要市| 南和县| 琼海市| 松江区| 九龙县| 通榆县| 来凤县|