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. java异常处理的设计

    有一句这样话:一个衡量Java设计师水平和开发团队纪律性的好方法就是读读他们应用程序里的异常处理代码. 本文主要讨论开发Java程序时,如何设计异常处理的代码,如何时抛异常,捕获到了怎么处理,而不是讲 ...

  2. Git & GitHub

    使用 Git 和 GitHub 有一段时间了,总结下经验. 起初接触 Git 是先遇到 GitHub 的,当时傻傻分不清这两者的区别,毕竟名字都那么像,刚开始只想用酷酷的方法 clone 代码(SSH ...

  3. 字符串匹配的KMP算法

    ~~~摘录 来源:阮一峰~~~ 字符串匹配是计算机的基本任务之一. 举例来说,有一个字符串”BBC ABCDAB ABCDABCDABDE”,我想知道,里面是否包含另一个字符串”ABCDABD”? 许 ...

  4. IIC总线解析

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

  5. MicroERP更新记录2.2:增加B/S查询功能

    提供电脑版及手机版两种浏览方式,仅仅作为一个DEMO展示,由于系统内置报表比较复杂,待广泛收集用户需求之后再逐步完善. 网页文件在安装包内web文件夹中. 下载地址:60.2.39.130/micro ...

  6. MicroERP软件更新记录1.0

    版本号:1.0.256 本次: 1\修复了选择货位时的BUG; 2\增加了物品资料由EXCEL表批量导入的功能; 3\物品资料增加了三个自定义属性; 4\优化了科目汇总账(余额表)算法; 5\应大家建 ...

  7. RoseRT配置高版本的编译器

    RoseRT配置高版本的VC++ ,我有VC++2008 Express ,实习时下载滴! 感谢Google,感谢大神地指导!困扰的问题终于解决,豁然开朗,so开始吧! 第一大步:重中之重, 确保nm ...

  8. 静态绑定网关,防止ARP攻击

    Windows XP 下 写个批处理文件:内容如下,名称自取 @echo offard -darp -s 192.168.1.1 00-14-78-ef-10-45//绑定IP地址 WIN 7 下 1 ...

  9. shared_ptr:资源管理利器

    如果你还在使用传统的C++,那么可以肯定堆内存的管理让你头痛过!在传统的C++领域,堆内存管理上我们能借用的现成工具就只有auto_ptr.但是很不幸用auto_ptr管理堆内存简直就是个错误.aut ...

  10. Activity Intent相关FLAG介绍

    先首先简单介绍下Task和Activity的关系   Task就像一个容器,而Activity就相当与填充这个容器的东西,第一个东西(Activity)则会处于最下面,最后添加的东西(Activity ...