• 类库_委托


    一:类库:

    说白了,就是让别人调用你写的方法,并且不让别人看到你是怎么实现的。

    如果有功能你不会做,需要别人帮忙,那么你的同事可以帮你写好一个类,然后你来调用这个类中的方法,完成你的项目。

    两种形式:

    1、C#源代码文件,包括在自己的项目中(这种可以查看到具体是怎么实现的,也可以更改)

    2、类库,.dll  (虽然无法查看,但是生活中很多都是这样的,毕竟不能让别人看到你的核心代码,为了保密)

    优点:你写的方法别人看不到实现过程,保密性强

    缺点:如果你写的方法有错误,别人无法更改

    ---------------------------------------------------------
    二:委托:
    可以理解为 函数的指针

    delegate - 定义关键词

    具体操作:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using 加减类;
    using ClassLibrary1;
    namespace 类库_委托
    {
        class Program
        {

            //声明委托类型
            public delegate int FirstDel(int aaa, int bbb);

            static void Main(string[] args)
            {
                  int one = 10;
                  int two = 20;

                  //创建委托变量,赋值,函数指向
                  FirstDel f1 = new JiaJian().Jia;

                  int c = f1(10, 20);

                  Console.WriteLine(c);
                  Console.ReadKey();

            }

        }

    }

    -----------------------------------------------------------

    var:万能类型

    object:所有类型的基类

    as:类型转换,如果转换不成功,不会报错,而是返回一个null

    例:

    ChengChu cc = ob as ChengChu;

    is:判断某个变量/对象,是不是某一种类型,返回bool值

    例:

    if (ob is ChengChu)
    {
    ChengChu cc = ob as ChengChu;
    }

    泛型集合: List<T>

    例:

    List<ChengChu> list = new List<ChengChu>();

    不固定长度,固定类型的一种集合

  • 相关阅读:
    Dockerfile指令
    oracle--ORA-38760
    守护进程--Supervisor
    oracle--sqlplus格式化输出
    oracle--10.2.0.3升级到11.2.0.4
    oracle--ORA-27125
    oracle--10安装问题
    oracle--CKPT
    oracle--LGWR
    Oracle--SMON
  • 原文地址:https://www.cnblogs.com/xtq0313/p/5861386.html
Copyright © 2020-2023  润新知