Visual C# 2010 Express: Specify default access modifier for new classes?

陌路散爱 提交于 2019-12-06 22:11:27

问题


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?


回答1:


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.




回答2:


You can Define Your Own Item Templates.

Visual Studio Templates

They are supported in the Express Edition as well: Creating Visual Studio Express Templates




回答3:


The article How to modify the default new class template for C# in Visual Studio 2008 or 2010? should help.



来源:https://stackoverflow.com/questions/4975318/visual-c-sharp-2010-express-specify-default-access-modifier-for-new-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!