亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 學院 > 開發設計 > 正文

C# for Beginner session 21 to 30

2019-11-17 02:39:13
字體:
來源:轉載
供稿:網友

C# for Beginner session 21 to 30

session 21Inheritance in c#

Why Inheritance

Pillars(支架) of Object Oriented PRogramming

1,Inheritance(繼承)

2,Encapsulation(封裝)

3,Abstraction(抽象類)

4,Poymorphism(多態)

1,Inheritance is one of the primary pillars of object oriented programming.

2,It allows code reuse.(重用)

3,Code reuse can reduce time and errors.

Note:You will specify(指定) all the common fields, properties,methods in the base class,which allows reusability.In the derived class you will only have fields, properties and methods,that are specific to them.

Inheritance Syntax

1,using : to inheritance

2,C# supports only single class inheritance.

3,C#supports multiple interface inheritance.

4,Child class is a specialization(特殊化) of base class.

5,Base classes are automatically instantiated(實例化) before derived classes.

6,Parent class constructor executes before Child Class constructor.

7,Using base keyWord to specify which Constructor methods .

session 22 Method hiding in c#

using the new keyword to hide a base class memeber.You will get a compiler(編譯器) warning,if you miss the new keyword.

Different ways to invoke a hidden base class member from derived class

1,Use base keyword.

2,Cast child type to parent type and invoke the hidden member

3,ParentClass PC = new ChildClass()

PC.HiddenMethod()

session 23Polymorphism in c#

Polymorphism is one of the primary pillars of object-oriented programming.

Polymorphism allows you to invoke derived class methods through a base class reference during runtime.

In the base class the method is declared virtual, and in the derived class we override the same method.

The virtual keyword indicates, the method can be overridden in any derived class.

session 24Difference between method overriding and method hiding

In method overriding a base class reference variable pointing to a child class object, will invoke the overriden method in the child class

In method hiding a base class reference variable pointing to a child class object, will invoke the hidden method in the base class.

session 25Method overloading in c#

Function overloading and method overloading terms are used interchangeably(互換).

Method overloading allows a class to have multiple methods with the same name, but, with a different signature(簽名). So, in C# functions can be overloaded based on the number, type(int, float etc), and kind(Value, Ref or Out) of parameters.

The signature of a method consists of the name of the method and the type, kind, and the number of its formal parameters. the signature of a method does not include the return type and the params modifier. So, it is not possible to overload a function, just based on the return type or params modifier.

session 26Why Properties

Marking the class fields public and exposing(暴露) to the external world is bad, as you will not have control over what gets assigned(賦值) and returned.

簡單的說,為了保護數據安全和完整性,所以需要屬性。

session 27Properties in C#

In C# to encapsulate(封裝) and protect fields we use properties

1,We use get and set accessors(訪問器) to implement properties

2,A property with only get accessor is a Read only property

3,A property with only set accessor is a Write only property

4,A property with both get and set accessor is Read/Write property

Note:The advantage of properties over traditional(傳統的) Get() and Set() methods is that, you can access(訪問) them as if they were public fields.

Auto implemented Properties

if there is no additional logic in the property accessors, then we can make use of auto implemented properties introduced in C# 3.0

Auto-implemented properties reduce the amount of code that we have to write.

When you use auto-implemented properties, the compiler creates a private, anonymous field that can only be accessed through the property's get and set accessors.

session 28Structs in C#

Structs

Just like calsses structs can have

1,Private Fields

2,Public Properties

3,Constructors

4,Methods

Object initializer syntax(語法), introduced in C# 3.0 can be used to initialize either a struct or a class

session 29Difference between classes and structs in c#

a struct is a value type where as a class is a reference type.(結構是值類型,類是引用類型)

All the differences that are applicable(適用于) to value types and reference types are also applicable to classes and structs

Structs are stored(存儲) on stack(棧), where as classes are stored on the heap(堆).

value type hold their value in memory where they are declared, but reference types hold a reference to an object in memory.

Value types are destroyed(銷毀) immediately(馬上) after the scope(應用范圍,也就是大括號) is lost, where as for reference types only the reference variable(變量) is destroyed after the scope is lost. The object is later destroyed by garbage collector.

when you copy a struct into another struct, a new copy of that struct gets created and modifications on one struct will not affect the values contained by the other struct.

when you copy a class into another class, we only get a copy of the reference variable, both the reference variables point to the same object on the heap. so, Operations on one variable will affect the values contanined by the other reference variable.

Classes Vs Structs

Structs can't have destructors, but classes can have destructors.(結構不能有析構函數,類可以有)

Structs cannot have explicit parameter less constructor where as a class can.(結構不可以有無參構造函數,類可以有)

Struct can't inherit from another class where as a class can. Both structs and classes inherit form an interface.(結構不能繼承類,類可以繼承機構,類和機構都可以繼承接口)

Example of structs in the .NET Framework -int(System.Int32),double(System.Double) etc.

Note1: A class or a struct cannot inherit form another struct. when Struct are sealed stypes.

Note2:How do you prevent a class from being inherited? Or what is the significance of sealed Keyword?

session 30Interfaces in c#

We create interfaces using interface keyword. just like classes interfaces also contains properties, methods, delegates or events, but only declarations and no implementations.

It is a compile time error to privide implementations for any interface member.

Interface members are public by default, and they don't allow explicit(顯式) access modifiers.

Interfaces cannot contain fields.(接口不可以包含字段)

If a class or struct inherits from an interface , it must provide implementation for all interface members. Otherwise, we get a compiler error.

A class or a struct can inherit from more than one interface at the same time, but where as, a class cannot inherit from more than oncee class at the same thime.

Interfaces can inherit from other interfaces. A class that inherits this interface must provide implementation for all interface members in the entire interface inheritance chain(一系列)

We cannot create an instance of an interface, but an interface reference variable can point to a derived class object.(接口不可以實例化,可是接口的引用可以指向子類,例如:IA a = new IA(); 這個是錯的,可是如果類A繼承了接口IA,那么這樣是可以的:IA a = new A();


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
在线中文字幕日韩| 九九精品视频在线观看| 亚洲图片欧美日产| 欧美性生交xxxxx久久久| 免费不卡欧美自拍视频| 国产精品美女久久| 国产精品久久久久久久久借妻| 日韩av免费在线播放| 亚洲精品视频在线观看视频| 亚洲美女久久久| 国产精品美女在线观看| www.国产精品一二区| 日本精品视频在线播放| 欧美性生交xxxxx久久久| 久久国产精品偷| 国产精品成av人在线视午夜片| 亚洲第一精品夜夜躁人人躁| 亚洲xxx大片| 久热99视频在线观看| 亚洲成av人乱码色午夜| 亚洲一区二区中文| 性金发美女69hd大尺寸| 欧洲成人在线视频| 深夜福利国产精品| 亚洲国产另类 国产精品国产免费| 精品国产乱码久久久久久婷婷| 国产69久久精品成人看| 国产日韩亚洲欧美| 国产一区二区三区日韩欧美| 久久久亚洲国产| 91九色国产社区在线观看| 欧美怡红院视频一区二区三区| 最新国产成人av网站网址麻豆| 国产精品久久99久久| 96pao国产成视频永久免费| 久久久亚洲精品视频| 欧美午夜精品久久久久久浪潮| 国产精品嫩草视频| 国产免费亚洲高清| 久久久久久久97| 亚洲精品小视频在线观看| 精品高清美女精品国产区| 久久精品国产亚洲精品2020| 日韩激情片免费| 北条麻妃99精品青青久久| 亚洲高清不卡av| 日韩av在线一区二区| 亚洲a∨日韩av高清在线观看| 欧美理论电影在线观看| 欧美日韩国产二区| 精品福利樱桃av导航| 国产丝袜一区视频在线观看| 欧美成人自拍视频| 亚洲精品福利视频| 日本精品一区二区三区在线播放视频| 国产高清在线不卡| 欧美午夜精品久久久久久久| 亚洲精品永久免费| 欧美高清videos高潮hd| 欧美日韩国产精品一区二区三区四区| 97在线看福利| 69视频在线播放| 欧美日韩综合视频网址| 91精品视频网站| 欧美日本在线视频中文字字幕| 欧美一级大片视频| 欧美性受xxxx黑人猛交| 国产精品一区二区av影院萌芽| 国产精品久久久久久久一区探花| 亚洲免费视频在线观看| 久久中文字幕视频| 欧美激情xxxxx| 在线播放日韩欧美| 91视频九色网站| 粉嫩av一区二区三区免费野| 亚洲精品国产福利| 另类少妇人与禽zozz0性伦| 欧美成人精品三级在线观看| 亚洲天天在线日亚洲洲精| 精品视频偷偷看在线观看| 色偷偷av一区二区三区乱| 亚洲自拍偷拍在线| 中日韩午夜理伦电影免费| 国产999精品| 97av视频在线| 精品动漫一区二区三区| 91理论片午午论夜理片久久| 亚洲精品suv精品一区二区| 日韩欧美国产网站| 91精品久久久久| 亚洲国产精彩中文乱码av| 日韩中文字幕精品视频| 久久综合网hezyo| 久久久精品国产| 国产91精品在线播放| 色在人av网站天堂精品| 3344国产精品免费看| 国产亚洲欧美另类中文| 日韩欧美国产高清91| 亚洲人午夜精品免费| 久久99久久99精品免观看粉嫩| 精品调教chinesegay| 免费99精品国产自在在线| 亚洲综合大片69999| 中文字幕国产日韩| 日韩欧美一区二区三区久久| 中文字幕亚洲二区| 久久99国产精品自在自在app| 91网在线免费观看| 国产精品1区2区在线观看| 国产精品久久久久久久久粉嫩av| 九色成人免费视频| 国产成人精品一区| 久久全球大尺度高清视频| 欧美成人精品一区二区三区| 久久精品中文字幕免费mv| 亚洲电影av在线| 精品视频在线导航| 亚洲国产精品成人av| 岛国av在线不卡| 亚洲精品成人免费| 日韩欧美成人精品| 国产精品视频免费观看www| 黑人欧美xxxx| 日韩在线精品一区| 91久久精品国产91久久| 欧美午夜视频在线观看| 欧美在线一区二区三区四| 91亚洲国产成人精品性色| 激情懂色av一区av二区av| 亚洲视频在线免费观看| 国产丝袜一区二区三区| 亚洲国产天堂久久综合| 国产精品一区二区性色av| 日韩欧美在线中文字幕| 国产欧美精品在线播放| 久久亚洲精品一区二区| 色综合亚洲精品激情狠狠| 午夜免费在线观看精品视频| 91国产精品电影| 伊人亚洲福利一区二区三区| 韩国日本不卡在线| 精品女同一区二区三区在线播放| 国产亚洲精品久久久久久| 国产日韩视频在线观看| 欧美综合国产精品久久丁香| 国产91精品久久久久久久| 亚洲free性xxxx护士hd| 一色桃子一区二区| 亚洲色图综合网| 久久综合伊人77777尤物| 中文字幕一区电影| 国产精品69精品一区二区三区| 久久久视频精品| 久久久久久久久91| 欧美激情一区二区三级高清视频| 亚洲精品视频免费| 亚洲欧美激情四射在线日| 日韩在线观看高清| 国产日韩欧美在线观看| 日韩精品黄色网| 91国产精品电影| 青青草原成人在线视频| 国精产品一区一区三区有限在线|