目录 / C#
C#
--- name: C# slug: csharp version: 1.0.1 description: Write robust C# avoiding null traps, async deadlocks, and LINQ pitfalls. metadata: {"clawdbot":{"emoji":"💜","requires":{"bins":["dotnet"]},"os":["linux","darwin","win32"]}} --- ## Quick Reference | Topic | File | |-------|------| | Null reference, nullable types | `nulls.md` | | Async/await, deadlocks | `async.md` | | Deferred execution, closures | `linq.md` | | Value vs reference, boxing | `types.md` | | Iteration, equality | `collections.md` | | IDisposable, using, finalizers | `dispose.md` | ## Critical Rules - `?.` and `??` prevent NRE but `!` overrides warnings — still crashes if null - `.Result` or `.Wait()` on UI thread — deadlock, use `await` or `ConfigureAwait(false)` - LINQ is lazy — `query.Where(...)` doesn't execute until iteration - Multiple enumeration of IEnumerable — may re-query database, call `.ToList()` first - Closure captures variable, not value — loop variable in lambda captures last value - Struct in async method — copied, modifications lost after await - String comparison culture — `StringComparison.Ordinal` for code, `CurrentCulture` for UI - `GetHashCode()` must be stable — mutable fields break dictionary lookup - Modifying collection while iterating — throws, use `.ToList()` to iterate copy - `decimal` for money — `float`/`double` have precision loss - `readonly struct` prevents defensive copies — use for performance - `sealed` prevents inheritance — enables devirtualization optimization
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。
存档时间线
| 版本 | 存档时间 | 内容哈希 | 内容 |
|---|---|---|---|
| v5 | 2026-09-28 17:52 | 59f00acd | 已过保留期 |
| v6 | 2026-09-29 02:32 | 30cf4b19 | 已过保留期 |
| v7 | 2026-09-28 21:28 | 59f00acd | 已过保留期 |
| v8 | 2026-09-29 12:07 | 30cf4b19 | 已过保留期 |
| v9 | 2026-09-29 16:22 | 59f00acd | 已过保留期 |
| v10 | 2026-09-30 04:11 | 30cf4b19 | 已过保留期 |
| v11 | 2026-09-30 11:27 | 59f00acd | 已过保留期 |
| v12 | 2026-09-30 23:34 | 30cf4b19 | 已过保留期 |
| v13 | 2026-10-01 06:32 | 59f00acd | 已过保留期 |
| v14 | 2026-10-01 18:15 | 30cf4b19 | 可取 |
版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。
提交举报 / 纠错
侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。