Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSharp #161

Open
magicdawn opened this issue May 2, 2023 · 2 comments
Open

CSharp #161

magicdawn opened this issue May 2, 2023 · 2 comments

Comments

@magicdawn
Copy link
Owner

No description provided.

@magicdawn
Copy link
Owner Author

常用工具

format

  • dotnet format SDK 内置, 无需安装, 尝试下来不知为何不起作用
  • 官方 vscode extension Omnisharp, format 不太好用, 时灵时不灵. 使用 .editorconfig, 修改后需要重启 C# extension
  • csharpier: https://csharpier.com/docs/Configuration

命令行

colors / progress-bars / widgets

https://spectreconsole.net/

Graphics

@magicdawn
Copy link
Owner Author

magicdawn commented May 2, 2023

Language

using

csharp 的 using System; 相当于 rust 的 use System::*;

举个例子 System.Console.WriteLine(string str), 在 using System 后, 可以直接 Console.WriteLine

global using

  • 相当于 prelude
  • 可以出现在任意 src 文件中, 只要能被编译器扫描到
  • 可以使用 <Using> tag in .csproj file

parameters

https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/named-and-optional-arguments

C# 的 parameters 可以 不使用形参名 / 使用形参名, 这个时候可以打乱顺序传参.
不得不说真高级, 比 swift 的函数参数使用智能.

object & collection initializers

using System.CommandLine;

var readCommand = new Command("read", "Read and display the file.")
            {
                fileOption,
                delayOption,
                fgcolorOption,
                lightModeOption
            };

简单说

  • new SomeClass { Field1 = 1, Field2 = 2 } 构造器没有参数 () 可以省略.
  • 对于实现了 IEnumerable 的类型, 并且有合适的 Add 方法, 则可以 new SomeClass{ add_element_1, add_element_2 }

上面的 new Command(){ fileOption... } 就是利用了 collection initializer 这个特性.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant