张龙豪 发表于 2012-10-26 00:00:47

结构体,数组,方法的重载,ref,out


1. 结构体,数组。


namespace Struct_array结构体数组{    //结构体的声明,关键字是Struct。    struct people    {       public char sex; //结构体里面不但能存放属性,还能存放方法。       public int age;//如果属性不用public修饰,外面就不能访问该属性。       public void sayHello() { Console.WriteLine("hello,Struct!"); }    }    class Program    {      static void Main(string[] args)      {            people Jim;//使用结构必须先声明变量。            Jim.age = 11;            Jim.sex='男';            Jim.sayHello();//结构体里面的方法调用            Console.WriteLine("Jim 今年"+Jim.age+"岁了。");            Program ss = new Program();            ss.arrayexpra();            Console.ReadKey();      }            public void arrayexpra()      {            int[] nums;                            nums = new int[] { 1, 2, 3 };            int[] names=new int[10]; //声明一个最大长度为十的数组;            int[] ages = { 3,2,1,4,5,8,7}; //直接声明一个数组。             Array.Sort(ages);//对数组排序                     for (int i = 0; i < ages.Length; i++)            {                Console.WriteLine(ages);            }            Array.Reverse(ages); //反转一个数组            for (int i = 0; i < ages.Length; i++)            {                Console.WriteLine(ages);            }            }    }}
页: [1]
查看完整版本: 结构体,数组,方法的重载,ref,out