2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

VisualStudio でファイルスコープ名前空間を優先に設定する

Posted at

VisualStudio でファイルを追加したとき、規定だと従来型の namespaceで生成されます。

namespace MyNamespace
{
    internal sealed class MyClass
    {
    }
}

C# 10 から ファイルスコープ 名前空間 が導入されました。

namespace MyNamespace;

internal sealed class MyClass
{
}

これ、個人的に大好き。

設定を変更して積極的に使っていきましょう。

手順

  1. [ツール] > [オプション] > [テキストエディタ―] > [C#] > [コードスタイル] > [全般]
  2. [コードブロックの優先順位] > [名前空間の宣言]
  3. [範囲指定されたファイル] を選択

image.png

ここに限ったことではないのですが、ちょいちょい日本語ローカライズに違和感を感じます・・・笑

.editorconfig を使用している場合はそっちで上書きされるので、そちらの設定も必要です。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?