多语言展示
当前在线:1215今日阅读:102今日分享:40

Visual Studio中代码段文件snippet的介绍

我们在平时编写代码的时候,经常会遇到一些重复出现的相似的代码片段。在Visual Studio中的工具中有一个代码段管理器,我们可以在代码段管理器里面管理我们的一些常用的重复代码。代码段可以使程序代码的编写更快、更容易、更可靠。在Visual Studio中是通过snippet文件(本质上是一个xml文件)来管理代码段,下面我们就对snippet文件做一下了解(以Visual C#的代码段为例)。
工具/原料

Visual Studio

方法/步骤
1

在Visual Studio中依次点击【工具】——【代码段管理器】,打开窗体【代码段管理器】。

2

在窗体【代码段管理器】中选中语言“Visual C#”,然后在“位置”下面的文件夹中选择文件夹“Visual C#”,里面有很多的snippet文件,假设选中try代码段的文件,在位置上会显示该文件的存储路径,在该路径中找到文件,并打开,如图所示。

3

下面介绍一下snippet文件中节点的意义:表示此代码段标题;<Shortcut>设置快捷键;<Description>对代码段的描述;<SnippetTypes>可以包含多个<SnippetType>,其取值有三种(Expansion、SurroundsWidth、Refactoring)。Expansion允许代码插入在光标处;SurroundsWith允许代码围绕在选中代码两边;Refactoring指定了C#重构过程中所使用的snippet,在自定义snippet中不能使用。如果改值不做设置,则snippet可以放在任何地方;<Snippet>节点是实现代码管理的地方,其包含四个子节点<Code>、<Declarations>、<Imports>、<References>,其中,我们的代码写在<Code>节点中。</p></div></div><div class="prev_next"> <div class="prev"> <span>上一篇:</span><a href="/eupaw.html">如何使用PLSQLDeveloper快速创建数据表</a> </div> <div class="next"> <span>下一篇:</span><a href="/eupay.html">mssql中 sysdatabases sysobjects syscolumns</a> </div> </div> </div> <div class="appleccmw content-right"> <div class="listmore">推荐信息</div> <div class="send_list"> <ul> <li><a href="/eupax.html" title="Visual Studio中代码段文件snippet的介绍"><span>1</span><h3>Visual Studio中代码段文件snippet的介绍</h3></a></li> <li><a href="/cnlec.html" title="小厨师教你如何去虾线"><span>2</span><h3>小厨师教你如何去虾线</h3></a></li> <li><a href="/cnleb.html" title="英雄之城II完整攻略 种族背景详解"><span>3</span><h3>英雄之城II完整攻略 种族背景详解</h3></a></li> <li><a href="/cnlea.html" title="酷家乐室内设计--灯光渲染独家高级技巧教程"><span>4</span><h3>酷家乐室内设计--灯光渲染独家高级技巧教程</h3></a></li> <li><a href="/cnldz.html" title="电脑基本工作原理"><span>5</span><h3>电脑基本工作原理</h3></a></li> <li><a href="/cnldy.html" title="怎样才能快速去除虾线?"><span>6</span><h3>怎样才能快速去除虾线?</h3></a></li> <li><a href="/cnldx.html" title="dnf混沌魔灵极限输出加点"><span>7</span><h3>dnf混沌魔灵极限输出加点</h3></a></li> <li><a href="/cnldw.html" title="龙将最有价值金将介绍"><span>8</span><h3>龙将最有价值金将介绍</h3></a></li> <li><a href="/cnldv.html" title="如何三招快速除虾线"><span>9</span><h3>如何三招快速除虾线</h3></a></li> <li><a href="/cnldu.html" title="计算机工作原理和发展历史(一)"><span>10</span><h3>计算机工作原理和发展历史(一)</h3></a></li> <li><a href="/cnldt.html" title="计算机的发展历程"><span>11</span><h3>计算机的发展历程</h3></a></li> <li><a href="/cnlds.html" title="外出和骨干教师培训感悟"><span>12</span><h3>外出和骨干教师培训感悟</h3></a></li> <li><a href="/cnldr.html" title="胃酸烧心吃什么好"><span>13</span><h3>胃酸烧心吃什么好</h3></a></li> <li><a href="/cnldq.html" title="露娜洁面仪如何使用"><span>14</span><h3>露娜洁面仪如何使用</h3></a></li> <li><a href="/cnldp.html" title="虾线怎么去除最简单"><span>15</span><h3>虾线怎么去除最简单</h3></a></li> <li><a href="/cnldo.html" title="有什么瘦大腿的方法吗"><span>16</span><h3>有什么瘦大腿的方法吗</h3></a></li> <li><a href="/cnldn.html" title="烟雨江湖冯老四在哪"><span>17</span><h3>烟雨江湖冯老四在哪</h3></a></li> <li><a href="/cnldm.html" title="CAD的工具栏怎么设定"><span>18</span><h3>CAD的工具栏怎么设定</h3></a></li> <li><a href="/cnldl.html" title="如何在草图注释下调出 CAD2014常用工具栏"><span>19</span><h3>如何在草图注释下调出 CAD2014常用工具栏</h3></a></li> <li><a href="/cnldk.html" title="CAD功能区如何调出呢?"><span>20</span><h3>CAD功能区如何调出呢?</h3></a></li> <li><a href="/cnldj.html" title="CAD2014常用工具栏不见应怎么办"><span>21</span><h3>CAD2014常用工具栏不见应怎么办</h3></a></li> </ul> <div class="clear"></div> </div> </div> </div> <div class="clear"></div> <div class="onjfeeds"></div><span class="onj_live"></span><span class="childonj"></span><div class="onj_location"></div><span class="buddhaonj"></span><div class="branchesccmw footer_service"> <a href="/sitemap.html" target="_blank">网站地图</a> <a href="/sitemap.xml" target="_blank">XML</a> <a href="/sitemap.txt" target="_blank">TXT</a> <a href="/rss.xml" target="_blank">RSS</a> <a href="/privacy.html" target="_blank">隐私政策</a> <a href="/service.html" target="_blank">服务条款</a> <a href="/agreement.html" target="_blank">使用条款</a> <div class="flagccmw footer_copyright clogWalletccmw">Copyright ©1996-2026 www.onijiang.com Corporation, All Rights Reserved</div> </div> <script src="/static/index1js/jquery-3.5.1.min.js" rel="external nofollow"></script> <script src="/static/js/share.js" rel="external nofollow"></script> <script src="/static/js/tran.js" rel="external nofollow"></script> <script src="/static/js/langs.js" rel="external nofollow" ></script> <div class="onj_happy"></div><span class="containeronj"></span><div class="baronj" id="baronj"></div><div id="Family_seal_onj"></div><script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https'){ bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else{ bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body> </html>