1. Different Kinds  of Type Members

 
     A type can define zero or more of the following kinds of members:
 
     Constants
          A constant is a symbol that identifies a never-changing data value
 
     Fields
          A field represents a read-only or read/write data value
 
     Instance constructors
          An instance constructor is a special method used to initialize a new object’s instance fields to a good initial state
 
     Type constructors
          A type constructor is a special method used to initialize a type’s static fields to a good initial state
 
     Methods
          A method is a function that performs operations that change or query the state of a type (static method) or an object (instance method)
 
     Operator overloads
          An operator overload is a method that defines how an object should be manipulated when certain operators are applied to the object
 
     Conversion operators
          A conversion operator is a method that defines how to implicitly or explicitly cast or convert an object from one type to another type
 
     Properties
          A property is a mechanism that allows a simple, field-like syntax for setting or querying part of the logical state of a type (static property) or object (instance property) while ensuring that the state doesn’t become corrupt. Properties can be parameterless (very common) or parameterful (fairly uncommon but used frequently with collection classes)
 
     Events
          A static event is a mechanism that allows a type to send a notification to one or more static or instance methods
 
     Types
          A type can define other types nested within it
 
2. Type Visiblity
 
     You can specify the type’s visibility as being either public or internal
 
     A public type is visible to all code within the defining assembly as well as all code written in other assemblies. 
 
     An internal type is visible to all code within the defining assembly, and the type is not visible to code written in other assemblies. 
 
     If you do not explicitly specify either of these when you define a type, the C# compiler sets the type’s visibility to internal (the more restrictive of the two).
 
     e.g
using System;
// The type below has public visibility and can be accessed by code
// in this assembly as well as code written in other assemblies.
public class ThisIsAPublicType { ... }
 
// The type below has internal visibility and can be accessed by code
// in this assembly only.
internal class ThisIsAnInternalType { ... }
 
// The type below is internal because public/internal
// was not explicitly stated
class ThisIsAlsoAnInternalType { ... }
 
3. Friend Assemlbies
 
     When an assembly is built, it can indicate other assemblies it considers “friends” by using the InternalsVisibleTo attribute defined in the System.Runtime.CompilerServices namespace. The attribute has a string parameter that identifies the friend assembly’s name and public key (the string you pass to the attribute must not include a version, culture, or processor architecture). 
Note that friend assemblies can access all of an assembly’s internal types as well as these type’s internal members.
 
4. Member Accessiblity
 
    
5. Static classes
     
     The compiler enforces many restrictions on a static class:
     .. The class must be derived directly from System.Object because deriving from any other base class makes no sense since inheritance applies only to objects, and you cannot create an instance of a static class.
     .. The class must not implement any interfaces since interface methods are callable only when using an instance of a class.
     .. The class must define only static members (fields, methods, properties, and events). Any instance members cause the compiler to generate an error. 
     .. The class cannot be used as a field, method parameter, or local variable because all of these would indicate a variable that refers to an instance, and this is not allowed. If the compiler detects any of these uses, the compiler issues an error.
 
6. Partial Classes, Structures, and Interfaces
 
     The partial keyword tells the C# compiler that the source code for a single class, structure, or interface definition may span one or more source code files. There are three main reasons why you might want to split the source code for a type across multiple files: 
     .. Source control
 
     .. Splitting a class or structure into distinct logical units within a single file
 
     .. Code spitters
 
     The partial keyword is applied to the types in all files. When the files are compiled together, the compiler combines the code to produce one type that is in the resulting .exe or .dll assembly file (or .netmodule module file).
 
7. Components, Polymorphism, and Versioning
 
     Component Software Programming (CSP)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

CLR via C# 3rd - 06 - Type and Member Basics的更多相关文章

  1. CLR via C# 3rd - 04 - Type Fundamentals

    1. System.Object        The runtime requires every type to ultimately be derived from the System.Obj ...

  2. 6.Type and Member Basics

    1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data val ...

  3. CLR via C# 3rd - 05 - Primitive, Reference, and Value Types

    1. Primitive Types        Any data types the compiler directly supports are called primitive types. ...

  4. #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

    #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)宏的运行机理:1. ( (TYPE *)0 ) 将零转型为TY ...

  5. C语言高级用法---typeof( ((type *)0)->member )和offset_of()

    前言 本文讲解typeof( ((type *)0)->member )的含义,并在此基础上学习offset_of()的用法.typeof( ((type *)0)->member ) A ...

  6. #define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

    #include <iostream> #define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) usi ...

  7. C++:Abstract class : invalid abstract return type for member function ‘virtual...’

    #include <iostream> #include <cmath> #include <sstream> using namespace std; class ...

  8. CLR via C# 3rd - 08 - Methods

       Kinds of methods        Constructors      Type constructors      Overload operators      Type con ...

  9. CLR via C# 3rd - 07 - Constants and Fields

    1. Constants        A constant is a symbol that has a never-changing value. When defining a constant ...

随机推荐

  1. 使用nodejs调用微信发送红包

    前置条件:申请微信发送红包的账户及其权限 依赖 blueimg-md5和 xmlreader 库 /common/weixin.js 源码 /** * Created by chent696 on 2 ...

  2. 【FPGA】【代码】资源优化,结构优化

    资源优化 原始资源 定义时初始化和复位电路初始化都起作用,删除定义的初值后 将always块描述的组合逻辑变为时序逻辑后

  3. IIC总线解析

    IIC简介: IIC 即Inter-Integrated Circuit(集成电路总线),这种总线类型是由飞利浦半导体公司在八十年代初设计出来的,主要是用来连接整体电路(ICS) ,IIC是一种多向控 ...

  4. js中,全局变量与直接添加在window属性的区别

    在js中定义的全局变量是挂在window下的,而window的属性也一样,那么这两者有什么区别呢? 其实这两者还是有小小的区别的,全局变量是不能通过delete操作符删除的,而直接定义在window上 ...

  5. SpringMVC-DispatcheServlet

    1 HandlerMapping->HandlerAdapter->ViewResolver ->HandlerExceptionResolver 2

  6. Jacoco入门

    Jacoco介绍 转自:wangmuming 的博客 Jacoco是一个开源的覆盖率工具.Jacoco可以嵌入到Ant .Maven中,并提供了EclEmma Eclipse插件,也可以使用JavaA ...

  7. python中if __name__ == '__main__': 的解析

    当你打开一个.py文件时,经常会在代码的最下面看到if __name__ ==  '__main__':,现在就来介 绍一下它的作用. 模块是对象,并且所有的模块都有一个内置属性 __name__.一 ...

  8. Maven 导出依赖Jar,生成source.jar,javadoc.jar

    下载最新版的Maven http://maven.apache.org/download.cgi    解压到本地文件夹 新建环境变量    MAVEN_HOME   maven解压目录 在path加 ...

  9. 《java异常的一些总结》

    关于Java中异常的一些总结: 3 有些时候,程序在try块里打开了一些物理资源(例如数据库连接,网络连接. 4 和磁盘文件等),这些物理资源都必须显示回收. 5 6 注意:Java的垃圾回收机制不会 ...

  10. C#语言Winform防SQl注入做用户登录的例子

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...