🤖
C#
Avoid common C# mistakes — null traps, async pitfalls, LINQ gotchas, and disposal leaks.
安全通过
💬Prompt
技能说明
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.Resultor.Wait()on UI thread — deadlock, useawaitorConfigureAwait(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.Ordinalfor code,CurrentCulturefor UI GetHashCode()must be stable — mutable fields break dictionary lookup- Modifying collection while iterating — throws, use
.ToList()to iterate copy decimalfor money —float/doublehave precision lossreadonly structprevents defensive copies — use for performancesealedprevents inheritance — enables devirtualization optimization
如何使用「C#」?
- 打开小龙虾AI(Web 或 iOS App)
- 点击上方「立即使用」按钮,或在对话框中输入任务描述
- 小龙虾AI 会自动匹配并调用「C#」技能完成任务
- 结果即时呈现,支持继续对话优化