Visual C# 2010 Express:为新类指定默认访问修饰符?

发布于 2024-10-17 02:15:51 字数 121 浏览 12 评论 0原文

每当我使用 Visual Studio 2010 Express C# 创建新类时,它都会创建不带访问修饰符的新类。十分之九我希望我的新课程公开。如何让 Visual Studio 默认创建带有“public”修饰符的空类模板?

Whenever I create new classes using Visual Studio 2010 Express C# it creates them with no access modifier. 9 times out of 10 I want my new classes to be public. How can I have Visual Studio create empty class templates with the "public" modifier by default?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

林空鹿饮溪 2024-10-24 02:15:51

诀窍是创建一个名为 Class 的新项目模板。然后当你执行添加>时新建类,将默认选择您的模板而不是内置的类模板。 (我不确定这种行为是否得到保证,但它可以在我的机器 (TM) 上运行。) 要创建模板:

  1. 右键单击您的项目并选择“添加”>“班级。您可以接受默认名称(Class1)——这只是一个临时文件。
  2. 修改生成的类,例如通过添加 public 修饰符。保存一切。
  3. 选择文件>导出模板。
  4. 选择项目模板并指定相关文件 (Class1.cs)。
  5. 单击“下一步”,直到到达“模板选项”页面。对于模板名称,输入 Class。
  6. 单击“完成”。
  7. 删除临时 Class1.cs 文件。

现在执行添加>类,您应该会看到默认使用您的类模板,而不是内置模板。

The trick is to create a new item template named Class. Then when you do Add > New Class, your template will be selected by default rather than the built-in Class template. (I am not sure if this behaviour is guaranteed but it Works On My Machine (TM).) To create the template:

  1. Right-click in your project and choose Add > Class. You can accept the default name (Class1) -- this is just a temporary file.
  2. Modify the generated class as, for example by adding the public modifier. Save everything.
  3. Choose File > Export Template.
  4. Choose Item Template and specify the relevant file (Class1.cs).
  5. Click Next until you get to the Template Options page. For the template name, enter Class.
  6. Click Finish.
  7. Delete the temporary Class1.cs file.

Now do an Add > Class and you should see your Class template being used by default instead of the built-in one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文