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

推荐订阅源

L
LINUX DO - 最新话题
V
Visual Studio Blog
博客园 - 司徒正美
小众软件
小众软件
量子位
J
Java Code Geeks
美团技术团队
Latest news
Latest news
T
Threatpost
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
酷 壳 – CoolShell
酷 壳 – CoolShell
C
CERT Recently Published Vulnerability Notes
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
大猫的无限游戏
大猫的无限游戏
I
Intezer
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
A
Arctic Wolf
罗磊的独立博客
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
NISL@THU
NISL@THU
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Project Zero
Project Zero
L
LINUX DO - 热门话题
博客园 - Franky
WordPress大学
WordPress大学
月光博客
月光博客
PCI Perspectives
PCI Perspectives
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
博客园 - 聂微东
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
Jina AI
Jina AI
爱范儿
爱范儿
博客园 - 叶小钗
T
Threat Research - Cisco Blogs
IT之家
IT之家
Security Archives - TechRepublic
Security Archives - TechRepublic
V
V2EX
博客园_首页
宝玉的分享
宝玉的分享

博客园 - 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 类型转换操作不会抛出异常.