美文网首页
Visual Studio代码段及快捷键

Visual Studio代码段及快捷键

作者: 五维思考 | 来源:发表于2020-04-06 13:20 被阅读0次

Visual Studio 中有很多代码段都可以直接简写然后按TAB快速输入编译器中,为了提高编程效率。

一、使用快捷键生成代码段

//1. 【 ~ 】  创建析构函数
Program()
{}
//2. 【 checked 】  创建checked块
checked
{}
//3. 【 class 】  创建类声明
class MyClass
{}
//4. 【 ctor 】  创建对应类的构造函数
public Program ()
{}
//5. 【 cw 】  创建对Console.WriteLine();的调用
Console.WriteLine();
//6. 【 do 】  创建do(while)循环
do
{}
while (true);
//7. 【 else 】  创建else块
else
{}
//8. 【 enum 】  创建enum声明
enum MyEnum
{}
//9. 【 for 】  创建for循环
for (int i = 0; i < length; i++)
{}
//10. 【 foreach 】  创建foreach循环
foreach (var item in collection)
{}
//11. 【 forr 】  创建for循环,在每次循环后递减循环变量
for (int i = length - 1; i >= 0; i--)
{}
//12. 【 if 】  创建if块
if (true)
{}
//13. 【 interface 】  创建interface声明
interface IInterface
{}
//14. 【 lock 】  创建lock块
lock (this) //this 代表表达式
{}
//15. 【 namespace 】  创建namespace声明
namespace MyNamespace
{}
//16. 【 prop 】  创建属性代码块
public int MyProperty { get; set;}
//17. 【 struct 】  创建struct声明
struct MyStruct
{}
//18. 【 svm 】  创建static viod声明
static void Main(string[] args)
{}
//19. 【 switch 】  创建switch代码块
switch (switch_on)  //switch_on 代表条件表达式
{
    default:
}
//20. 【 try 】  创建try - catch代码块
try
{}
catch (Exception)
{
    throw;
}
//21. 【 unchecked 】  创建unchecked代码块
unchecked
{}
//22. 【 unsafe 】  创建unsafe代码块
unsafe
{}
//23. 【 using 】  创建using指令
using (resource)    //resource为要使用的资源
{}
//24. 【 while 】  创建while循环
while (true)
{}

二、代码段管理器

  1. 工具-》代码段管理器
  2. 选择Visual C#


    image.png
  3. 将复制的目录在文件夹中打开,复制其中的一个文件,以propfull.snippet为例


    image.png
  4. 将复制出的文件双击默认用vs打开


    image.png
  5. 修改Title 和Shortcut节点 为propn(这个可以自己改,改成什么快捷键就是什么),Description是注释说明可以修改


    image.png
  6. 修改生成的代码片段


    image.png

修改后

image.png
  1. 关闭vs重新打开 键入propn按tap键 生成代码


    image.png

相关文章

网友评论

      本文标题:Visual Studio代码段及快捷键

      本文链接:https://www.haomeiwen.com/subject/wzwgphtx.html