zoukankan      html  css  js  c++  java
  • c# 第三课 类

    类: 其中的成员变量和成员函数有public,private,protected,internal,protected internal五种

    Access-modifiers;

    public : the type or member can be  accessed by any other code in the same assembly or another assembly that reference it.

    private : the type or member can only be accessed by code in the same class or struct.

    protected : the type or member can only be accessed by code in the same or struct, or in a derived class. 

    internal : the type or member can be accessed by any code in the same assembly,but not from another assembly.

    protected internal : the type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.

    深拷贝和浅拷贝:

    对于类来说,浅拷贝只是拷一个指针。拷贝与被拷贝的内容占用同一片内存区域,删除一个变量时,另一个变量也为空。深拷贝则是重新开辟一块内存区域。两片内存区域存相同的内容。删除其中一个变量时,对另一个变量没有影响。

    this 关键字:refers to the current instance of an object. used in 5 ways.

    1 public void SomeMethod(int hour)

    {

    this.hour = hour;

    }

    2 class myClass

    {

        public void Foo(otherClass otherObject)

        {

           otherObject.bar(this);

        }

    }

    3 with indexers

    4 to call oneoverloaded constructor from another

      class myClass

      {

          public myClass(int i)

          public myClass():this(42)

      }

    5 to explicitly invoke methods and members of a class, as a form of documentation:

    public void Method(int y)

    {

       int x = 0;

       x = 7;

       y = 8;

       this.z = 5;

       this.Draw();

    }

    静态类不能实例化

    静态类是密封的,不能从它派生类型

    静态类不能包含非静态成员,也不能有构造方法。

    面向对象的三个特点:封装,多态,继承。

  • 相关阅读:
    团队个人冲刺day08
    4.26 jQuery AJAX load() 方法
    4.23 jquery
    4.22 AJAX技术
    4.21 正则表达式
    4.20
    4.15 重写团队作业1
    4.12 重写团队作业1
    4.9 团队作业1
    4.7 团队作业1
  • 原文地址:https://www.cnblogs.com/GSONG/p/4378842.html
Copyright © 2011-2022 走看看