类 对象

来源:互联网 发布:mac 待机快捷键 编辑:程序博客网 时间:2024/06/01 12:59
1,对象是类  new出来的。。 属性包括两个方法  get set
2,方法  方法是通过指定 修饰符 返回值类型 方法名称 参数列表(参数)  方法签名+方法体
    (1)形参 实参 类型相匹配obj类型
    (2)值类型参数
引用类型参数:比如数组,一个改变影响另一个
out类型参数:出参  必须在引用的函数中赋值(优点 返回多个返回值)只从本函数传到Main  单向传递参数
               static void Main(string[] args)
//{ int i=0;//不必赋值
        //    Add(out  i);
        //    Console.WriteLine(i);
//static void Add(out int i)
        //{
        //    i = 100;//必须赋值;
        //}
        ////out相当于把 i 转换成引用类型
ref类型参数:双向传递参数 带进 带出;
static void Main(string[] args)
        {
            int i = 10;
            Add(ref i);
            Console.WriteLine(i);
        }
    static void Add(ref int i)
    {
        Console .WriteLine (i);
    i=100;//不必赋值 因为可以接受main函数的i
    }
params类型参数:只能用于一维数组
  static void Main(string[] args)
        {
            Add(1, 1, 2, 3, 5, 5325);
        }
    static void Add(params int[]arr)
    {
        foreach (int i in arr)
        Console.WriteLine(i);
    }

 static void Main(string[] args)
        {int [] arr=new int [3] {1,2,3};
            Add(arr);
            Add(12, 3);
        }
    static void Add(params int[]arr)
    {
        foreach (int i in arr)
        Console.WriteLine(i);
    }
3,分部方法  ,,必须出现在分部类中
分部类是partial关键定义的,分部类可以分布在几个文件夹中的,由多个程序员编写,但很少用!可以有ref 不可以有out 默认访问修饰符private
4,扩展方法   已有的类型加了方法  尽量使用继承  不使用扩展 但string无子类 所以必须扩展   静态类!
5,匿名方法
6,









0 0
原创粉丝点击