首页 > 代码库 > ASP.NET基础

ASP.NET基础

using System;namespace ConsoleApp{    class Program    {        /// <summary>        /// 入口        /// </summary>        /// <param name="args"></param>        static void Main(string[] args)        {            #region 交换两个变量的值            //int num1 = 5;            //int num2 = 6;            //Console.WriteLine(" num1={0}\r\n num2={1}", num1, num2);            //int temp = num1;            //num1 = num2;            //num2 = temp;            //Console.WriteLine(" num1={0}\r\n num2={1}", num1, num2);            //Console.ReadKey();            #endregion            #region 求两个数的最大值            //int num1 = 5;            //int num2 = 8;            //int num3 = GetMax(num1, num2);            //Console.WriteLine("最大值为:{0}", num3);            //Console.ReadKey();            #endregion            #region 1-100之间所有奇数的和            //int result = 0;            //for (int i = 1; i <= 100; i++)            //{            //    if (i % 2 != 0)            //    {            //        result += i;            //    }            //}            //Console.WriteLine("1-100之间所有奇数的和为:{0}", result);            //Console.ReadKey();            #endregion            #region 找数组中最大的数            //int[] array = new int[] { 5, 4, 7, 9, 6, 3, 1 };            //int max = array[0];            //for (int i = 0; i < array.Length; i++)            //{            //    if (array[i] > max)            //    {            //        max = array[i];            //    }            //}            //Console.WriteLine("数组中最大的值为:{0}", max);            //Console.ReadKey();            #endregion            #region 时间格式转换            //string time = "2014年6月7号";            //string msg = FormatConversion(time);            //Console.WriteLine(msg);            //Console.ReadKey();            #endregion            Person per = new Person();            per.Name = "刘先生";            per.Sex = "";            per.Age = 22;            per.SayHi();            Employee emp = new Employee();            emp.Name = "孙悟空";            emp.Sex = "";            emp.Age = 5000;            emp.Salary = 10000;            emp.SayHi();            Console.ReadKey();        }        /// <summary>        /// 求两个数的最大值        /// </summary>        /// <param name="num1"></param>        /// <param name="num2"></param>        /// <returns></returns>        public static int GetMax(int num1, int num2)        {            return num1 > num2 ? num1 : num2;        }        /// <summary>        /// 时间格式转换        /// </summary>        /// <param name="time"></param>        /// <returns></returns>        public static string FormatConversion(string time)        {            char[] cha = time.ToCharArray();            for (int i = 0; i < cha.Length; i++)            {                switch (cha[i])                {                    case 0: cha[i] = ; break;                    case 1: cha[i] = ; break;                    case 2: cha[i] = ; break;                    case 3: cha[i] = ; break;                    case 4: cha[i] = ; break;                    case 5: cha[i] = ; break;                    case 6: cha[i] = ; break;                    case 7: cha[i] = ; break;                    case 8: cha[i] = ; break;                    case 9: cha[i] = ; break;                }            }            return new string(cha);        }    }}

person:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp{    public class Person    {        private string _name;        private string _sex;        private int _age;        /// <summary>        /// 姓名        /// </summary>        public string Name        {            get { return _name; }            set { _name = value; }        }        /// <summary>        /// 性别        /// </summary>        public string Sex        {            get { return _sex; }            set { _sex = value; }        }        /// <summary>        /// 年龄        /// </summary>        public int Age        {            get { return _age; }            set { _age = value; }        }        public virtual void SayHi()        {            Console.WriteLine("我叫:{0},性别:{1},今年:{2}岁", Name, Sex, Age);        }    }}
View Code

Employee:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace ConsoleApp{    public class Employee : Person    {        private double _salary;        /// <summary>        /// 工资        /// </summary>        public double Salary        {            get { return _salary; }            set { _salary = value; }        }        public override void SayHi()        {            Console.WriteLine("我叫:{0},性别:{1},今年:{2}岁,工资:{3}", Name, Sex, Age, Salary);        }    }}
View Code

 

ASP.NET基础