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

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - {:)

[译]删除IE收藏夹下的“链接”文件夹 Javascript Cheat Sheet(Javascript 速查手冊) CSS Cheat-Sheet(CSS速查手冊) 我们不需要企业偶像,我们需要企业英雄 [轉]jQuery selectors (JQuery选择器) 和JQuery Cheat sheet (JQuery 速查手冊) YKWIM - {:) - 博客园 the status code returned from the server was:500 Don't use GetType() with Page.ClientScript.RegisterClientScriptBlock() DNS 服務器地址被篡改 Outlook2007 連接到Exchange Server 失敗 装了KIS2009之后 10月22日链接篇: ASP.NET, Visual Studio, WPF 和 Silverlight - Scott Guthrie 博客中文版 - 博客堂 The Coding Standard Communication with the underlying transaction manager has failed 程序员八荣八耻 SCORM -LMS-SCO Data课件与平台交互机制圖解 解决安装SP3后,Window Media Player 播放器不能播放的问题 解決VS無法拖拽控件到頁面的問題 Some JavaScript Source Code About WebInput Use Refresh() function right in WebGrid with javascript
Discover the difference among Types: is operator,typeof keyword and GetType method
{:) · 2008-11-14 · via 博客园 - {:)
  • is operator - shows if object x is of type y. If this condition is true, then you can cast the instance to the given type. This accounts for inheritance. For example, all types (such as System.Int32) inherit from System.Object.  And 'is' Check if we can cast  that type  safety to  this type. Also We can use the '' as ''
  • keyword when we want to see if we can cast form one type to another,if  the cast is not valid then the ''as'' operator will return null.

  • GetType() method - a method on System.Object (and therefore available to all types) that returns the Type of the object. The Type class has a "FullName" property which returns a string of the name. Notice that you can tell the name of immediate type here, but it doesn't inheritance. For example, for an object on type "System.Int32"  the "is" keyword accounts for the current type (int) and the base type (object). GetType requires an instance and returns a type.
  • typeof keyword - Takes a Class an returns a Type (almost the inverse of typeof).
  • "instance.GetType()==typeof(Class) " is not always equal  "instance is Class".there will one  problem when we use inheritance.

    I.E:

        BasePage inherits form Page,and BasePage inherits also from object,so if we

        test for(new BasePage()).GetType()==typeof(object) it'll return false because

         the types are different,but when we test using the is operator it's true.

         ((new BasePage()) is object) is true because (new BasePage()) is an object of   type BasePage, and also a Page and an object. The types might be different , but is operator checks whethere we can cast safely to this type.

    Notice :

    this same pattern can be applied to both value types (like a System.Int32) and reference types (like an XmlDocument):

    typeof() is an operator and GetType() is a method defined in System.Object an both of them returns and object of System.Type.

    System.Type.GetType is more than 7 times slower (on my dual core machine) than typeof.

    There are times when GetType is useful, but if the Type is well known to you then use typeof.

    use:

    Type aType = typeof(DateTime);

    instead of:

    System.Type.GetType("System.DateTime");

    By using the is operator, GetType method, and typeof keyword, we can effectively manage type information and solve several problems in various ways.