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

推荐订阅源

V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
Netflix TechBlog - Medium
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
V
V2EX
IT之家
IT之家
J
Java Code Geeks
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
GbyAI
GbyAI
D
Docker
S
Secure Thoughts
Recent Announcements
Recent Announcements
Webroot Blog
Webroot Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
博客园_首页
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Security Archives - TechRepublic
Security Archives - TechRepublic
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
N
News | PayPal Newsroom
S
Security @ Cisco Blogs
I
InfoQ
Last Week in AI
Last Week in AI
SecWiki News
SecWiki News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
T
Troy Hunt's Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Attack and Defense Labs
Attack and Defense Labs
美团技术团队
T
The Blog of Author Tim Ferriss
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
B
Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Scott Helme
Scott Helme
T
Tor Project blog
Know Your Adversary
Know Your Adversary
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
Recorded Future
Recorded Future
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
G
Google Developers Blog

博客园 - 子风

Android相关转载帖子 c++ 函数的工作原理 C和C++的存储模式 VS2005配置开发ARM c++ 虚析构函数的思考 arm-linux-g++ 下交叉编译libxml2 (转)Eclipse代码提示功能设置(Java & C/C++) linux下面eclipse的c++配置 VS2008 配置boost 用VS.NET2008打包程序遇到不可恢复的生成错误的解决方案 推荐一个原型的设计软件 Mockups For Desktop Grid++Report——推模式下填充子报表 Failure sending mail - 子风 XP下IIS错误:Server Application Error css总结 asp.net缓存-数据依赖缓存 - 子风 - 博客园 .net 测试工具 .net 发送Email 利用7z来分卷压缩文件
c# 对象的创建过程
子风 · 2010-08-05 · via 博客园 - 子风

1:分配静态成员的内存空间,值类型为0,引用类型为null

2: 执行静态成员的赋值。

3:执行静态的构造函数。

4:分配成员的内存空间,值为0,引用类型为null

5:执行成员的赋值。

6:分配基类静态成员的内存空间,值为0,引用类型为null

7:执行基类静态成员的赋值。

8:执行基类的静态构造函数。

9:基类的成员的声明和赋值。

10:基类的构造函数

11:构造函数

注:静态的成员和构筑函数只运行一次。

代码

class Program
    {
        
static void Main(string[] args)
        {
            ClB b 
= new ClB();
            b 
= new ClB();
            Console.ReadLine();
        }
    }
public class ClsA
    {
        
private static readonly string strA = "A";
        
private string name;
        
public string Name
        {
            
set { this.name = value; }
            
get{return name;}
        }
        
static ClsA()
        {
            Console.WriteLine(strA);
            strA 
= "A Changed";

            Console.WriteLine(strA);
            Console.WriteLine(

"A staic constructor!");
        }
        
public ClsA()
        {
            Console.WriteLine(
"A constructor!");
        }
    }
public class ClB:ClsA
    {
        
private static readonly string strB = "B";
        
private int age =12;static ClB()
        {
            Console.WriteLine(strB);
            strB 
= "B Changed!";
            Console.WriteLine(strB);
            Console.WriteLine(
"B static constructor!");
        }
public ClB()
         
        {
            Console.WriteLine(age);
            Console.WriteLine(
"B constructor!");
        }
    }

学习,积累中......