Visual Studio常用代码片段整理(一)

使用方式:if后两下Tab键

1.if

if (true)
{

}

 

2.#region   代码块

#region MyRegion

#endregion

 

3.checked   检查数据是否发生了溢出(参考:https://www.xin3721.com/ArticlecSharp/c6701.html)

checked
{

}

上述是对整个代码块的数据溢出检查,checked还有对单个变量的检查如

 int i = int.MaxValue;
 int m = checked(i + 10);

以上代码运行时会再执行 int m = checked(i + 10); 报错(因为变量m超出了int类型的最大值),如果不加checked,则数据溢出也不会抛出,此时m=-2147483639

 

4.class   快速新建类

class MyClass
{

}

 

5.ctor   快速创建构造函数

 public MyClass()
{

}

 

6.cw  快速生成输出打印

 Console.WriteLine();

 

7.do   快速生成循环

 do
{

} while (true);

 

8.else   快速生成else语句块

 else
{

}

 

9.enum   快速生成枚举

 enum MyEnum
{

}

 

10.equals   快速生成比较

复制代码
public override bool Equals(object obj)
{
   //       
   // See the full list of guidelines at
   //   http://go.microsoft.com/fwlink/?LinkID=85237  
   // and also the guidance for operator== at
   //   http://go.microsoft.com/fwlink/?LinkId=85238
   //

   if (obj == null || GetType() != obj.GetType())
   {
       return false;
   }

            // TODO: write your implementation of Equals() here
   throw new NotImplementedException();
   return base.Equals(obj);
}

        // override object.GetHashCode
public override int GetHashCode()
{
   // TODO: write your implementation of GetHashCode() here
   throw new NotImplementedException();
   return base.GetHashCode();
}
复制代码

 

posted @   真真真甜  阅读(48)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示