惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
博客园 - 司徒正美
Microsoft Azure Blog
Microsoft Azure Blog
J
Java Code Geeks
The Cloudflare Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
Recent Announcements
Recent Announcements
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
WordPress大学
WordPress大学
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
T
Tor Project blog
阮一峰的网络日志
阮一峰的网络日志
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Hacker News
The Hacker News
F
Full Disclosure
有赞技术团队
有赞技术团队
H
Help Net Security
Security Latest
Security Latest
P
Palo Alto Networks Blog
MyScale Blog
MyScale Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
GRAHAM CLULEY
P
Privacy International News Feed
P
Proofpoint News Feed
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
罗磊的独立博客
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Latest news
Latest news
Jina AI
Jina AI
Stack Overflow Blog
Stack Overflow Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News: Ask HN
Hacker News: Ask HN
爱范儿
爱范儿
T
Threat Research - Cisco Blogs
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
N
Netflix TechBlog - Medium
D
DataBreaches.Net
L
LINUX DO - 热门话题
Application and Cybersecurity Blog
Application and Cybersecurity Blog
L
Lohrmann on Cybersecurity
O
OpenAI News
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

博客园 - bullfinch

Notes of "The Unbridged Pentium 4" - Pentium 4 System Overview Notes of "The Unbridged Pentium 4" - Pentium 4 Road Map Notes of "The Unbridged Pentium 4" - Overview of the Processor Role Notes of "Pentium Processor System Architecture" - Pentium Signal Interface (part) Notes of "Pentium Processor System Architecture" - Mutiple Processors and the MESI Model Notes of "Pentium Processor System Architecture" - The Functional Units & Pentium Cache Overview AMD Opteron Architecture related Fedora Core 3 挂载FAT32分区以及中文显示和输入 摄像头设置事件 linux下安装HP NC6000无线网卡(HP W500) C#学习笔记(八) TreeView.AfterCheck和TreeNode.Checked赋值的问题 C#学习笔记(七) C#学习笔记(六) C#学习笔记(五) 图像中密集点群的定位 C#学习笔记(四) 中兴ZXDSL831立式蓝猫自动拨号+NAT+DHCP设置 关于变参(zz)
C#学习笔记(三)
bullfinch · 2005-01-24 · via 博客园 - bullfinch

1) 意外地发现,多个类可以定义在一个文件中,不知道为什么,本来认为一个类、接口、结构只能在一个与自己名字相同的文件中定义。


2) struct不支持继承和析构,且它是数值类型而不是参考类型,所以会被box和unbox。struct也不支持自定义的无参数构造函数;如果自定义了构造函数,必须初始化每个域。struct还不支持对域初始化。


3) 在C++中,new总是在堆上创建对象;在C#中,类是在堆上创建的,但struct是在栈上创建的。而且,当new被省略的时候,构造函数不会被调用。使用struct前必须显式的初始化(确定赋值)谨慎使用省略new创建struct!


4) 属性实际上还是成员方法,在对成员变量进行初始化之前,无法调用任何方法,这就是为什么无法直接对属性赋初值。


5) 实现一个interface,即定义了implements关系。interface总是隐式地标记为public的,因为它要被其他类使用。


6) 多个interface实现了多重继承(C#不支持直接通过多个类来实现多重继承)。interface则通过extend来实现“继承”,同样可以是多重的。


7) interface不能直接实例化,但可以通过实例化一个实现了这个interface的class,并将这个对象用于interface的实例化。


8) 用interface参考来访问接口方法要比用实现interface的类的对象来访问要好,这样可以利用多态性。


9) is可用于判断某个对象是否可以被cast给某个interface,但效率较低。as则把is和cast操作结合在一起,检验和“赋值”同时进行。


10) 以一个实现了interface的类为基类,派生出新类,即使用这个新类的对象来创建一个interface的实例,这个实例调用的非virtual/override方法都是基类而不是子类的。即,interface的实例总是以实现了它的那个类的对象的形式出现。


11) 遇到两个接口有相同方法的时候,将其中一个接口的那个方法显式实现,且这个方法总是隐式public的,不能是abstract, virtual, override或new的,且直接对对象调用这个方法总是调用的隐式实现的那个,要访问显式实现的方法,只能通过接口。


12) 显式实现某个方法还可以使这个方法对于实现类的对象来说是不可用的,它只能被接口使用,但由于失去了virtual性能,实现类的派生类必须重新实现这个方法。


13) interface在继承的过程中可以通过重名和显式实现来隐藏某些成员。


14) 当使用数值类型(如struct)或sealed类来实现interface时,请使用对象本身来访问interface成员,而不要用interface的参考来访问,因为box将会使原本和所建立的副本分开,导致混乱。