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 ...
随机推荐
- ssh 密码登陆
概要: 首先 自己生成秘钥 其次 用已经生成的秘钥 实现 用秘钥登陆的功能(在别的机器上部署的道理相同) 辅助: 登陆工具 Tera Term linux版本:cen ...
- 苹果公布WWDC2016时间 并做了个程序员情怀网页
新浪手机讯 4月19日上午消息,苹果公司今日正式确定2016年全球开发者大会(WWDC)开幕时间:6月13-17日,并做了个非常有意思的代码风格页面. 网友戏称这个页面只有程序员们才能看懂,它的首页是 ...
- mysql语句中日期函数和日期的加减运算
一.秒数和时钟格式的互相转化 SEC_TO_TIME(seconds) 返回seconds参数,变换成小时.分钟和秒,值以'HH:MM:SS'或HHMMSS格式化,取决于函数是在一个字符串还是在数字. ...
- 查找“asdfjvjadsffvaadfkfasaffdsasdffadsafafsafdadsfaafd” 该字符串中有多少个af
package lovo.bean; import java.util.Scanner; public class Java { @param args public static void main ...
- Python 数据类型笔记
Python有以下几种数据类型:1.字符串(str),2.布尔类型(bool),3.数字(int,float),4.列表(list),5.元组(tuple),6.字典(dict).1. 字符串. 对于 ...
- My97DatePicker的使用
一. 简介 1. 简介 目前的版本是:4.8 2. 注意事项 My97DatePicker目录是一个整体,不可破坏里面的目录结构,也不可对里面的文件改名,可以改目录名 My97DatePicker.h ...
- Linux 终端常用快捷键
Tab 自动补全 Ctrl+L 清屏 Ctrl+A 移动到头 Ctrl+E 移动到尾 Ctrl+左键头 左移一个单词 Ctrl+右箭头 右移一个单词 Ctrl+U 删除左边所有字符 Ctrl+K 删除 ...
- 项目组J2ee程序员的标志,你中招没 转载+评论
原文在此 校园级别的程序员的标志: 代码中最多的是嵌套if(null == xxx),还要告诉你,null必须写在前面,我靠. 防止把==写成=,c语言时代常犯的错误.由于null不能做左值,在写=的 ...
- Linq 备忘录
public class CTest { public int i { get; set; } public string j { get; set; } } 一.Range var items=En ...
- Android数据库 — — —查询数据
package com.example.datebasetest; import android.content.ContentValues;import android.database.Curso ...