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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 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将会使原本和所建立的副本分开,导致混乱。