1.All Types Are Derived from System.Object

The CLR requires all objects to be created using the new operator(Employee e = new Employee("ConstructorParam1");)

  the new operator does:

  1.It calculates the number of bytes required

  2.It allocates memory for the object,then all of these bytes are set to zero

  3.initializes the object’s type object pointer and sync block index members

  4.The type’s instance constructor is called

  returns a reference (or pointer) to the newly created object.The CLR uses a garbage-collected environment that automatically detects the new operator

2.Casting Between Types  

an object is type safety,because GetType() is nonvirtual.

it necessary to cast an object to various types. The CLR allows you to cast an object to its type or to any of its base types.

the proper way to declare the PromoteEmployee method would be to specify an Employee type instead of an Object type as its parameter so that the compiler produces a compiletime error

3.Casting with the C# is and as Operators

  checks whether an object is compatible with a given type

  operator is typically used,but the CLR is actually checking the object’s type twice and certainly comes at a performance cost

  a way to simplify this code and improve its performance by providing an as operator.

  CTE:compile-time error;RTE:run-time error

4.Namespaces and Assemblies

  Namespaces:

  1.the logical grouping of related types,(model中的的entity)

  2.developers typically use them to make it easier to locate a particular type(逻辑处理)

  the compiler needs to ensure:1.every type referenced exists;2.using type in the correct way:

  When checking for a type’s definition, the compiler must be told which assemblies to examine by using the /reference compiler switch。The compiler will scan all of the referenced assemblies looking for the type’s definition.

  After the compiler finds the proper assembly, the assembly information and the type information is emitted into the resulting managed module’s metadata.

  two namesapce both hace a type called Widget(),they does something entirely different.

  1.

  

  2.

  

  

  Be aware that a namespace and an assembly (the file that implements a type) aren’t necessarily related.

  1.In particular, the various types belonging to a single namespace might be implemented in multiple assemblies.(the System.IO.FileStream type is implemented in the MSCorLib.dll assembly, and the System.IO.FileSystemWatcher type is implemented in the System.dll assembly.)

  2.A single assembly can contain types in different namespaces. (the System.Int32 and System.Text.StringBuilder types are both in the MSCorLib.dll assembly.)

  3.When you look up a type in the .NET Framework SDK documentation, the documentation will clearly indicate the namespace that the type belongs to and also the assembly that the type is implemented in.(ResXFileRef type is part of the System.Resources namespace and that the type is implemented in the System.Windows.Forms.dll assembly)

  

5.How Things Relate at Run Time

  1.explain the relationship at run time between types, objects, a thread’s stack, and the managed heap

  2.explain the difference between calling static methods, instance methods, and virtual methods

  

  1.

  

  2.As the just-in-time (JIT) compiler converts M3’s Intermediate Language (IL) code into native CPU instructions, it notices all of the types that are referred to inside M3: Employee, Int32, Manager, and String。

  the CLR ensures that the assemblies that define these types are loaded. Then, using the assembly’s metadata, the CLR extracts information about these types and creates some data structures to represent the types themselves.

  assume that the Int32 and String type objects have already been created

  

  all objects on the heap contain two overhead members: the type object pointer and the sync block index.

  the CLR has ensured that all of the type objects required by the method are created and the code for M3 has been compiled, the CLR allows the thread to execute M3’s native code.

  3. prologue code executes, memory for the local variables must be allocated from the thread’s stack。

  the CLR automatically initializes all local variables to null or 0 (zero) as part of the method’s prologue code

  

  4.M3 executes its code:This causes an instance of the Manager type, a Manager object, to be created in the managed heap.The new operator returns the memory address of the Manager object, which is saved in the variable e (on the thread’s stack).

  

  Whenever a new object is created on the heap, the CLR automatically initializes the internal type object pointer member to refer to the object’s corresponding type object.Furthermore, the CLR initializes the sync block index and sets all of the object’s instance fields to null or 0 (zero) prior to calling the type’s constructor, a method that will likely modify some of the instance data fields.

  5.M3 calls Employee’s static Lookup method.returns the address of this object. The address is saved in the local variable e

  

  When calling a static method,the JIT compiler locates the type object that corresponds to the type that defines the static method.Then, the JIT compiler locates the entry in the type object’s method table that refers to the method being called, JITs the method (if necessary), and calls the JITted code.

  6.M3 calls Employee’s nonvirtual instance GetYearsEmployed method.The integer is saved in the local variable year

  

  When calling a nonvirtual instance method, the JIT compiler locates the type object that corresponds to the type of the variable being used to make the call.

  In this case, the variable e is defined as an Employee. (If the Employee type didn’t define the method being called, the JIT compiler walks down the class hierarchy toward Object looking for this method. It can do this because each type object has a field in it that refers to its base type; this information is not shown in the figures.)

  Then,the JIT compiler locates the entry in the type object’s method table that refers to the method being called, JITs the method (if necessary), and then calls the JITted code.

  7.M3 calls Employee’s virtual instance GetProgressReport method.Manager’s GetProgressReport implementation is called because e refers to a Manager object

  

  When calling a virtual instance method, the JIT compiler produces some additional code in the method, which will be executed each time the method is invoked. This code will first look in the variable being used to make the call and then follow the address to the calling object.

  the code will examine the object’s internal type object pointer member; this member refers to the actual type of the object. The code then locates the entry in the type object’s method table that refers to the method being called, JITs the method (if necessary), and calls the JITted code.

  question:Employee and Manager type objects both contain type object pointer

members.

  answer:type objects are actually objects themselves. When the CLR creates type

objects, the CLR must initialize these members.when the CLR starts running in a process, it immediately creates a special type object for the System.Type type

  

  the System.Type type object is an object itself and therefore also has a type object pointer member in it, and it is logical to ask what this member refers to. It refers to itself because the System.Type type object is itself an “instance” of a type object.

  System.Object’s GetType method simply returns the address stored in the specified object’s type object pointer member.

  In other words, the GetType method returns a pointer to an object’s type object, and this is how you can determine the true type of any object in the system (including type objects).

4、Type fundamentals的更多相关文章

  1. 2、一、Introduction(入门):1、Application Fundamentals(应用程序基础)

    一.Introduction(入门) 1.Application Fundamentals(应用程序基础) Android apps are written in the Java programmi ...

  2. 类型转换bin()、chr()、ord() 、int()、float()、str()、repr()、bytes()、tuple(s )、 list(s )   、unichr(x ) 、 ord(x )  、 hex(x )  、          type()数据类型查询

    1.bin() 将整数x转换为二进制字符串,如果x不为Python中int类型,x必须包含方法__index__()并且返回值为integer: 参数x:整数或者包含__index__()方法切返回值 ...

  3. TYPES、DATA、TYPE、LIKE、CONSTANTS、STATICS、TABLES

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  4. linux中查找命令find、locate、whereis、which、type区别

    linux中查找命令find.locate.whereis.which.type区别 1. find Java代码 find是最常见和最强大的查找命令,你可以用它找到任何你想找的文件.与查询数据库(/ ...

  5. python中3个帮助函数help、dir、type的使用

    1.help函数:查看模块.函数.变量的详细说明: 查看模块 help("modules") 查看包  help("json") 查看类 help(json.J ...

  6. Intent的属性及Intent-filter配置——Data、Type属性与intent-filter配置

    Data属性通常用于向Action属性提供操作的数据,Data属性接受一个Uri对象,一个Uri对象通常通过如下形式的字符串来表示: content://com.android.contacts/co ...

  7. 004-linux命令-搜索命令find、locate、whereis、which、type

    一.概述 使用linux系统难免会忘记文件所在的位置,可以使用以下命令对系统中的文件进行搜索. 1.1.find 语法:find <指定目录> <指定条件> <指定动作& ...

  8. linux命令总结之查找命令find、locate、whereis、which、type

    我们经常需要在系统中查找一个文件,那么在Linux系统中我们如何准确高效的确定一个文件在系统中的具体位置呢?一下我总结了在linux系统中用于查找文件的几个命令. 1.find命令 find是最常用也 ...

  9. Spring Framework 官方文档学习(四)之Validation、Data Binding、Type Conversion(一)

    题外话:本篇是对之前那篇的重排版.并拆分成两篇,免得没了看的兴趣. 前言 在Spring Framework官方文档中,这三者是放到一起讲的,但没有解释为什么放到一起.大概是默认了读者都是有相关经验的 ...

随机推荐

  1. Android 二维码扫描框 加四个角及中间横线自动下滑

    红色为加四个角  黄色为扫描线自动下滑 /* * Copyright (C) 2008 ZXing authors * * Licensed under the Apache License, Ver ...

  2. 161108、Java IO流读写文件的几个注意点

    平时写IO相关代码机会挺少的,但却都知道使用BufferedXXXX来读写效率高,没想到里面还有这么多陷阱,这两天突然被其中一个陷阱折腾一下:读一个文件,然后写到另外一个文件,前后两个文件居然不一样? ...

  3. 161028、Nginx负载均衡实现tomcat集群方案简要小结

    重点两部分:一.负载均衡二.tomcat集群 所谓tomcat集群,就是可以向外提供并行服务的多台机器,任何一台服务器宕机,其它服务器可以替代它向外提供服务,而不影响用户访问. Nginx是一个常用的 ...

  4. 给MD5加上salt随机盐值加密算法实现密码安全的php实现

    给MD5加上salt随机盐值加密算法实现密码安全的php实现 如果直接对密码进行散列,那么黑客可以对通过获得这个密码散列值,然后通过查散列值字典(例如MD5密码破解网站),得到某用户的密码.加上sal ...

  5. jstl简介

    JavaServer Page Standard Tag Library是一个有用的JSP标签的集合,它封装了许多JSP应用程序通用的核心功能. JSTL支持常见的,结构性任务,如迭代和条件,标签为操 ...

  6. Temporary InMemory Tables [AX 2012]

    Temporary InMemory Tables [AX 2012] This topic has not yet been rated - Rate this topic Updated: Oct ...

  7. du -sh

    评估文件空间利用率: [root@vm-xiluhua][/home]$ du -sh /home 409M /home --exclude选项,排除指定模式的文件的大小 [root@vm-xiluh ...

  8. 函数参数为int*和int&的区别

    参数为int*,表明参数为指针,调用的时候需要地址,如f(&a): 参数为int&,传引用参数,调用时f(a),“引用类型的形参就通过形实结合,成为实参的一个别名,对形参的任何操作也就 ...

  9. Asp.net Vnext api CORS( 跨域)

    概述 跨域资源共享(CORS )是一种网络浏览器的技术规范,它为Web服务器定义了一种方式,允许网页从不同的域访问其资源.而这种访问是被同源策略所禁止的.CORS系统定义了一种浏览器和服务器交互的方式 ...

  10. ThinkPHP使用PHPmailer发送Email邮件

    下面介绍thinkphp如何使用phpmailer发送邮件,使用这个邮件发送类,配置好参数后,一句话即可发送邮件.仅适合于thinkphp框架. 第一步,下载类库 将Mail.class.php复制到 ...