日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > C# >内容正文

C#

the Differences between abstract class interface in C#接口和抽象类的区别

發(fā)布時間:2023/12/19 C# 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 the Differences between abstract class interface in C#接口和抽象类的区别 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

????abstract class and interface in C# look like much, but sometimes they get the similiar use. However, there are still much differences between them. here we go.
????抽象類和接口初看上去很象,但是還是有很多區(qū)別的。
?? a) Interface Grammar接口語法
?? [public|protected|internal|private] interface interfaceName
????{
????????public int add(int x,int y);
//this?is?error! interface memeber can not be described with any?characters?to?declare its access attribute.
//接口中任何成員和屬性不能被任何修飾符修飾來表明其訪問屬性!
????????int add(int x,int y);
//this is right!
????????int Count{get;} //interface property接口屬性
????????string this[int index]{get;set;}//index interface?接口索引
????}

????Difference:????
????????1. in interface, all interface members can not be?decorated with any?other access tag,such as public,private.etc.
????????2. in?abtract class,?such case is just on the opposite.
????
????b) abstract class Grammar 抽象類語法
????????[public|protected|internal|private] abstct class className
????????{
????????????public abstract int?add(int x,int y);
????????????//it's ok, but that forbidden in?interface!
????????????//在abstract class中,類成員可以有各種修飾符。如果該類成員沒有被implement,那么該類一定要被標示為abstact方法。否則出錯!當然也可以實現(xiàn)該方法。如下multiply方法所示
????????????public virtual int?multiply(int x,int y)
????????????{
????????????????return x*y;
????????????}
????????}

????????Difference:
????????1.in interface,?all interface memebers can not be implemented. and it's just an declaration? for?other class?which will inherented from it and?implemented all of them.
????????在接口中,所有接口成員都不能被實現(xiàn),它只是一個申明而已,其他類繼承自該接口,并且要實現(xiàn)該接口中的所有成員。
????????2 in abstract class, its member can be implemented?,otherwise must be decorated with abstract that is the same with interface .?of course,?any class inherented from this? must implemented all?its abstract method.?of course,?u can?also override the method?that?has already implemented method.
????????在抽象類中,其成員可以被實現(xiàn),如果不實現(xiàn)的話,其方法成員一定要被標標示為abstract.?同時,任何繼承于該抽象類的類必須要實現(xiàn)其所有標示為abstract的方法,這點與interface相同。或者該類也可以override該抽象類中的method.?這一點interface絕對不可能,因為interface中根本沒有實現(xiàn)過,何來override?

????????

轉載于:https://www.cnblogs.com/Winston/archive/2008/04/23/1166876.html

總結

以上是生活随笔為你收集整理的the Differences between abstract class interface in C#接口和抽象类的区别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。