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

推荐订阅源

博客园_首页
The GitHub Blog
The GitHub Blog
美团技术团队
Know Your Adversary
Know Your Adversary
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Register - Security
The Register - Security
Stack Overflow Blog
Stack Overflow Blog
Attack and Defense Labs
Attack and Defense Labs
G
Google Developers Blog
I
InfoQ
博客园 - 司徒正美
T
Troy Hunt's Blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
S
Security Affairs
M
MIT News - Artificial intelligence
Simon Willison's Weblog
Simon Willison's Weblog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Tailwind CSS Blog
量子位
Vercel News
Vercel News
月光博客
月光博客
V
Vulnerabilities – Threatpost
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 最新话题
F
Full Disclosure
The Hacker News
The Hacker News
Hacker News: Ask HN
Hacker News: Ask HN
T
Tor Project blog
A
Arctic Wolf
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Forbes - Security
Forbes - Security
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
GbyAI
GbyAI
B
Blog RSS Feed
V
Visual Studio Blog
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs

博客园 - Cameo

解决VSTO项目重定向到.NET Framework 4的编译和运行时错误 Excel 应用程序如何创建数据透视表 值类型与引用类型 Visual studio tools for office体系结构 VSTO开发团队成立 15. Command 命令(行为型模式) 14. Template Method模板方法(行为型模式) 13. Proxy代理(结构型模式) 12. Flyweight享元(结构型模式) 11. Facade外观[门面模式](结构型模式) 10. Decorator 装饰(结构型模式) 9. Composite 组合(结构型模式) 8. Bridge 桥接(结构型模式) 7. Adapter 适配器(结构型模式) 6. Prototype 原型(创建型模式) 5. Factory Method 工厂方法(创建型模式的基础) 4.Builder 建造者(生成器)(创建型模式) 书籍收藏 3. Abstract Factory 抽象工厂(创建型模式)
C#类型转换
Cameo · 2008-10-07 · via 博客园 - Cameo

 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5
 6namespace TypeCast
 7{
 8    internal class Employee
 9    
10    
11    }

12    internal class Manager : Employee
13    
14    
15    }

16    class Program
17    {
18        static void Main(string[] args)
19        {
20            Manager m = new Manager();
21            Employee e = m as Employee;
22            if (e != null)
23            {
24                Console.WriteLine(e.GetType().ToString());
25            }

26
27            PromoteEmployee(m);
28            //the cast above no fails:Cause Manager is derived from Employee
29
30
31            Object o = new object();
32            Employee e1 = o as Employee;
33            if (e1 != null)
34            {
35                Console.WriteLine(e.GetType().ToString());
36            }

37            //the cast above fails:no exception is thrown,but e1 is set to null
38
39            PromoteEmployee(o);
40            //the cast above fails: exception is thrown
41        }

42
43        public static void PromoteEmployee(Object o)
44        {
45            Employee e = (Employee)o;
46            Console.WriteLine(e.GetType().ToString());
47        }

48    }

49

注意:用As 类型转换操作不会抛出异常.