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

推荐订阅源

V
Visual Studio Blog
C
Cisco Blogs
Help Net Security
Help Net Security
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Scott Helme
Scott Helme
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
M
MIT News - Artificial intelligence
L
LINUX DO - 热门话题
I
InfoQ
GbyAI
GbyAI
NISL@THU
NISL@THU
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Engineering at Meta
Engineering at Meta
H
Hackread – Cybersecurity News, Data Breaches, AI and More
TaoSecurity Blog
TaoSecurity Blog
Simon Willison's Weblog
Simon Willison's Weblog
A
About on SuperTechFans
Spread Privacy
Spread Privacy
月光博客
月光博客
W
WeLiveSecurity
AWS News Blog
AWS News Blog
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Security Latest
Security Latest
人人都是产品经理
人人都是产品经理
PCI Perspectives
PCI Perspectives
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Azure Blog
Microsoft Azure Blog
Hugging Face - Blog
Hugging Face - Blog
S
SegmentFault 最新的问题
T
Troy Hunt's Blog
Martin Fowler
Martin Fowler
The Hacker News
The Hacker News
T
Tor Project blog
C
CERT Recently Published Vulnerability Notes
Apple Machine Learning Research
Apple Machine Learning Research
Stack Overflow Blog
Stack Overflow Blog
K
Kaspersky official blog
Cloudbric
Cloudbric
H
Help Net Security
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
D
DataBreaches.Net
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tenable Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
博客园 - Franky
L
LINUX DO - 最新话题
MyScale Blog
MyScale Blog

博客园 - huadust

msdn 网络编程 委托用法 注册表操作 DateTime各种用法 [转]将dll汇入exe 用DataTable构建树 Lock Review String Review DataTable opertion Drag DataGridView Data To TreeView 2009_01_15_星期三 2009_01_02_星期五 2008_12_31_星期三 2008_12_24_星期三 2008_12_20_星期六 2008_12_17_星期三 2008_12_06_星期六 2008_12_04_星期四
Class Review
huadust · 2009-07-21 · via 博客园 - huadust

1. definition

class TestClass
{
   
//methods, properties, fields, events, delegates
   
//nested classes, only nested class can use: protected and private
}

2. inherit

class ClassA { }                               //无继承
class DerivedClass: Base Class { }      //单一继承
class InterClass: Int1, Int2 { }           //接口继承
class IDClass: BaseClass, Int { }         //复合继承

3. Members
      Constructor
      Destructor
不能在结构中定义析构函数。只能对类使用析构函数; 一个类只能有一个析构函数; 无法继承或重载析构函数; 无法调用析构函数。它们是被自动调用的; 析构函数既没有修饰符,也没有参数
程序员无法控制何时调用析构函数,因为这是由垃圾回收器决定的垃圾回收器检查是否存在应用程序不再使用的对象。如果垃圾回收器认为某个对象符合析构,则调用析构函数(如果有)并回收用来存储此对象的内存。程序退出时也会调用析构函数。
可以通过调用 Collect 强制进行垃圾回收,但大多数情况下应避免这样做,因为这样会导致性能问题。
不应使用空析构函数。如果类包含析构函数,Finalize 队列中则会创建一个项。调用析构函数时,将调用垃圾回收器来处理该队列。如果析构函数为空,只会导致不必要的性能损失

class Car
{
    
~Car()  // destructor
    {
        
// cleanup statements
    }//该析构函数隐式地对对象的基类调用 Finalize。这样,前面的析构函数代码被隐式地转换为以下代码:
    protected override void Finalize()
    {
        
try
        {
            
// Cleanup statements
        }
        
finally
        {
            
base.Finalize();
        }
    }
}

      Constant
      Field
      Method
      Property
      Indexer      

class SampleCollection<T>
{
    
private T[] arr = new T[100];
    
public T this[int i]
    {
        
get
        {
            
return arr[i];
        }
        
set
        {
            arr[i] 
= value;
        }
    }
}

      Operator
      Event
      Delegate
      Class
      Interface
      Struct

3. Generic Class

class BaseNode { }
class BaseNodeGeneric<T> { }// concrete type
class NodeConcrete<T> : BaseNode { }//closed constructed type
class NodeClosed<T> : BaseNodeGeneric<int> { }//open constructed type 
class NodeOpen<T> : BaseNodeGeneric<T> { }

泛型类封装不是特定于具体数据类型的操作,最常用于集合。

//No error
class Node1 : BaseNodeGeneric<int> { }//Generates an error
//class Node2 : BaseNodeGeneric<T> {}//Generates an error
//class Node3 : T {}

非泛型类(换句话说,即具体类)可以从封闭式构造基类继承,但无法从开放式构造类或裸类型形参继承,因为在运行时客户端代码无法提供实例化基类所需的类型实参

class BaseNodeMultiple<T, U> { }//No error
class Node4<T> : BaseNodeMultiple<T, int> { }//No error
class Node5<T, U> : BaseNodeMultiple<T, U> { }//Generates an error
//class Node6<T> : BaseNodeMultiple<T, U> {}

从开放式构造类型继承的泛型类必须为任何未被继承类共享的基类类型参数提供类型变量

void Swap<T>(List<T> list1, List<T> list2)
{
    
//code to swap items
}void Swap(List<int> list1, List<int> list2)
{
    
//code to swap items
}

开放式构造类型和封闭式构造类型可以用作方法参数