D 语言编程:教程与参考
本文是关于 D 语言编程的教程与参考资料,由 Ali Çehreli 撰写。内容涵盖了 D 语言的基础知识,包括 Hello World 程序、基本类型、变量、控制流、数组、字符串、函数、类、模板、并发等。提供了多种获取方式,如纸质版、电子书、互动课程等,并附带代码示例和关键词索引。文章还提供了 D 语言相关的其他资源链接。
D 语言编程 – 教程与参考 Ali Çehreli
其他 D 语言资源
Main Page > Books > Prg in D [ ↢ Prev ] [ Next ↣ ]
Programming in D
![]()
本书也可以通过以下方式获取:
- 纸质版或 Kindle 版(这是一个使 The D Language Foundation 受益的 Amazon 联盟链接,它总是欢迎捐款。)
- 作为 educative.io 上的互动课程
- 作为电子书,定价为 pay-what-you-want 在 Gumroad
- 并且可以在这里免费获取 PDF, EPUB, AZW3, 和 MOBI 格式。
章节
- Andrei Alexandrescu 的前言
- 前言
- Hello World 程序
main - writeln 和 write
- 编译
- 基本类型
char int double (and more) - 赋值和求值顺序
= - 变量
- 标准输入输出流
stdin stdout - 从标准输入读取
- 逻辑表达式
bool true false ! == != < <= > >= || && - if 语句
if else - while 循环
while continue break - 整数和算术运算
++ -- + - * / % ^^ += -= *= /= %= ^^= - 浮点类型
.nan .infinity isNaN - 数组
[] .length ~ ~= - 字符
char wchar dchar - 切片和其他数组特性
.. $ .dup capacity - 字符串
char[] wchar[] dchar[] string wstring dstring - 重定向标准输入和输出流
- 文件
File - auto 和 typeof
auto typeof - 名称作用域
- for 循环
for - 三元运算符 ?:
?: - 字面量
- 格式化输出
writef writefln - 格式化输入
- do-while 循环
do while - 关联数组
.keys .values .byKey .byValue .byKeyValue .get .remove in - foreach 循环
foreach .byKey .byValue .byKeyValue - switch 和 case
switch, case, default, final switch - enum
enum .min .max - 函数
return void - 不可变性
enum const immutable .dup .idup - 值类型和引用类型
& - 函数参数
in out ref inout lazy scope shared - 左值和右值
auto ref - 惰性运算符
- 程序环境
main stderr - 异常
throw try catch finally - scope
scope(exit) scope(success) scope(failure) - assert 和 enforce
assert enforce - 单元测试
unittest - 契约式编程
in out - 生命周期和基本操作
- null 值和 is 运算符
null is !is - 类型转换
to assumeUnique cast - 结构体
struct . {} static, static this, static ~this - 可变数量的参数
T[]... __MODULE__ __FILE__ __LINE__ __FUNCTION__ (and more) - 函数重载
- 成员函数
toString - const ref 参数和 const 成员函数
const ref, in ref, inout - 构造函数和其他特殊函数
this ~this this(this) opAssign @disable - 运算符重载
opUnary opBinary opEquals opCmp opIndex (and more) - 类
class new - 继承
: super override abstract - Object
toString opEquals opCmp toHash typeid TypeInfo - 接口
interface static final - destroy 和 scoped
destroy scoped - 模块和库
import, module, static this, static ~this - 封装和保护属性
private protected public package - 通用函数调用语法 (UFCS)
- 属性
- 结构体和类的契约式编程
invariant - 模板
- Pragma
- alias 和 with
alias with - alias this
alias this - 指针
* & - 位运算
~ & | ^ >> >>> << - 条件编译
debug, version, static if, static assert, __traits - is 表达式
is() - 函数指针、委托和 Lambda 表达式
function delegate => toString - 带有结构体和类的 foreach
opApply empty popFront front (and more) - 嵌套函数、结构体和类
static - Union
union - 标签和 goto
goto - 元组
tuple Tuple AliasSeq .tupleof foreach - 更多模板
template opDollar opIndex opSlice - 更多函数
inout pure nothrow @nogc @safe @trusted @system CTFE __ctfe - Mixin
mixin - Ranges
InputRange ForwardRange BidirectionalRange RandomAccessRange OutputRange - 更多 Ranges
isInputRange ElementType hasLength inputRangeObject (and more) - static foreach
- 并行
parallel task asyncBuf map amap reduce - 消息传递并发
spawn thisTid ownerTid send receive (and more) - 数据共享并发
synchronized, shared, shared static this, shared static ~this - 纤程
call yield - 内存管理
calloc realloc emplace destroy .alignof - 用户自定义属性 (UDA)
@ - 运算符优先级
dlang.org
Rights
代码示例作为
关键词索引