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 - 04 - Type Fundamentals
1. System.Object The runtime requires every type to ultimately be derived from the System.Obj ...
- 6.Type and Member Basics
1.The Different Kinds of Type Members 1.Constants:a symbol that identifies a never-changing data val ...
- CLR via C# 3rd - 05 - Primitive, Reference, and Value Types
1. Primitive Types Any data types the compiler directly supports are called primitive types. ...
- #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)宏的运行机理:1. ( (TYPE *)0 ) 将零转型为TY ...
- C语言高级用法---typeof( ((type *)0)->member )和offset_of()
前言 本文讲解typeof( ((type *)0)->member )的含义,并在此基础上学习offset_of()的用法.typeof( ((type *)0)->member ) A ...
- #define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#include <iostream> #define IOFFSETOF(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) usi ...
- C++:Abstract class : invalid abstract return type for member function ‘virtual...’
#include <iostream> #include <cmath> #include <sstream> using namespace std; class ...
- CLR via C# 3rd - 08 - Methods
Kinds of methods Constructors Type constructors Overload operators Type con ...
- 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 ...
随机推荐
- [开发笔记]-未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出【转载自:酷小孩】
原文地址:http://www.cnblogs.com/babycool/p/3199158.html 今天打算用VisualStudio2012做一个js效果页面测试的时候,打开VS2012新建项目 ...
- Windows平台下Git服务器搭建
第一步:下载Java,下载地址:http://www.java.com/zh_CN/ 第二步:安装Java.安装步骤不再详述. 第三步:配置Java环境变量. 右键”计算机” => ”属性” = ...
- 用ant组建测试框架
有时候由于公司网络或其它原因,无法采用maven,这时ant是一个比较理想的选择.以下是以ant为例,搭建一个测试框架 项目结构如下图: build.properties代码如下: # The sou ...
- 在CentOS6.8上面安装Python3.5
以前每次装Linux,升级Python,都会一堆问题,然后Google,本来想着记录一下,结果问题太多了,也就记不住了,这次特地记了下来. 在CentOS6.8上面安装Python3.5我的系统是Ce ...
- keil uvision3 添加 STC单片机库
本人工作以来,一直从事仪表程序维护和开发工作,使用的清一色的都是microchip单片机。现在弄一个光立方的小玩意,需要用STC单片机。它有特点很明显,方便、资料多、最重要的一点便宜。 网上下载的ke ...
- hibernate的一种报错
Exception in thread "main" java.lang.NoClassDefFoundError: javax/tools/StandardJavaFileMan ...
- git分支
git的分支是一个版本库.检出分支分支会影响暂存区和工作区的内容. 创建分支:git branch [testing] 检出分支:git checkout [testing] 创建并且检出分支:$gi ...
- HBase查找一条数据的过程
HBase中的Client如何路由到正确的RegionServer 在HBase中,大部分的操作都是在RegionServer完成的,Client端想要插入,删除,查询数据都需要先找到相应的 Regi ...
- script标签里的defer属性
入职新公司,看代码的时候注意到有的script标签中有一个defer属性,查了一下.在这里分享出来. 需要注意的有三点,其中前两点是在错误中分辨出来的: 错误来源:http://www.w3schoo ...
- firefox浏览器中silverlight无法输入问题
firefox浏览器中silverlight无法输入问题 今天用firefox浏览silverlight网页,想在文本框中输入内容,却没想到silverlight插件意外崩溃了.google一下,发现 ...