c# 之学习9 params 可变参数

来源:互联网 发布:顺德出格软件 编辑:程序博客网 时间:2024/05/16 17:25
namespace ConsoleApplication3{    public enum qqState    {        qqonline,        qqoffline,        qqme,        qqbusy,    }    public struct Person    {        public string _name;        public int _age;        public Gender _gender;    }    public enum Gender    {        男,        女    }    class Program    {        //可变参数 params 在方法的形参中是唯一 且在方法形参的最后一个        public static void Sun(string name, params int[] arr)        {            int S = 0;            for (int i = 0; i < arr.Length; i++)            {                S += arr[i];            }            Console.WriteLine("{0}和是:{1}",name,S);        }        static void Main(string[] args)        {            //#region            //将enum 类型转换成int            //枚举和int类型是相互兼容的 可以相互转换            //int n = 0;            //qqState qa;            //n = (int)qqState.qqbusy;            //Console.WriteLine(n);            //#endregion            //#region            //将enum   转成int            //枚举和int类型是相互兼容的 可以相互转换            //qqState qb;            //int m = 2;            //qb = (qqState)m;            //Console.WriteLine(qb);            //#endregion            //#region            //将枚举类型转换string            //qqState qc;            //qc = qqState.qqoffline;            //string str = qc.ToString();            //Console.WriteLine(str);            //#endregion            //#region            //将string转换成int            //Console.WriteLine("将string转换成int");            //qqState qd;            //string s = "2";            //qd = (qqState)Enum.Parse(typeof(qqState), s);            //Console.WriteLine(qd);            //是数字 如果枚举中没有就会输出数字 不会抛出异常            //s = "5";            //qd = (qqState)Enum.Parse(typeof(qqState), s);            //Console.WriteLine(qd);            //是数字 如果枚举中没有 就会抛出异常            //s = "qqme";//s="sdf";//这样会报错            //qd = (qqState)Enum.Parse(typeof(qqState), s);            //Console.WriteLine(qd);            ////#endregion            int[] s = { 100, 230, 12 };            Sun("sun1", 100, 230, 12);            Sun("sun2", s);            Person lsPerson;            lsPerson._name = "SDE";            Console.ReadKey();        }    }}
params   在函数形参中的唯一 和末位性质
原创粉丝点击