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. T-SQL中找出一个表的所有外键关联表

    二种方法(下例中表名为T_Work) 1.SQL查询系统表 SELECT 主键列ID=b.rkey ,主键列名=(SELECT name FROM syscolumns WHERE colid=b.r ...

  2. [移动端]rem适配

    原理:给html根节点设置一个基础font-size值,然后页面的所有元素布局均相对于该font-size值采用rem单位设定.font-size的取值通过js计算. 但字体不用rem单位,原因如下: ...

  3. C++中的数组

    数组名作为参数时,传递的是数组的首地址, 主调函数中实参数组元素个数不应该少于形参数组的元素个数 把数组名作为参数时,一般不指定数组第一维的大小 即使指定,编译时也会被忽略的.

  4. (1)WCF少废话系列之 _Hello WCF!

    本节旨在通过实例的方式让初学者对WCF有一个感性的认识,坚持由特殊到普遍再由普遍到特殊的认知规律. WCF(Windows Communication Fundation),微软分布式通信架构的集合, ...

  5. Redis并发锁控制

    为了防止用户在页面上重复点击或者同时发起多次请求,请求处理需要操作redis缓存,这个时候需要对并发边界进行并发锁控制,实现思路: 由于每个页面发起的请求带的token具备唯一性,可以将token作为 ...

  6. 动态加载jQuery

    success: function(data){ for(var i in data){ $('.x-details>ul:eq(0)').append("<li>&quo ...

  7. .net 读取Excel文件报错

    错误内容 Microsoft Office Excel 不能访问文件“D:\WWWRoot\Website\Test\Excels\Test1.xls”. 可能的原因有: 1 文件名称或路径不存在. ...

  8. what is SVD and how to calculate it

    http://web.mit.edu/be.400/www/SVD/Singular_Value_Decomposition.htm SVD是研究地震波运动极性化的一个方法.

  9. 将excel文件批量转成pdf

    防止数据编辑.改动带来的不一致性,常常要将excel文件转成pdf文件再共享.发送给对方.有时excel文件还挺多,手头上保存实在是太慢了.就考虑用VBA批量转置. 掌握几个东西,就比较容易了: 1. ...

  10. python实现的视频下载工具you-get,支持多个国内外主流视频平台

    RT,you-get 是一个视频离线下载工具, https://github.com/soimort/you-get 另一个同类工具 youtube-dl 也是python 实现,虽然名为 youtu ...