调试快捷键
F6: 生成解决方案
Ctrl+F6: 生成当前项目
F7: 查看代码
Shift+F7: 查看窗体设计器
F5: 启动调试
Ctrl+F5: 开始执行(不调试)
Shift+F5: 停止调试
Ctrl+Shift+F5: 重启调试
F9: 切换断点
Ctrl+F9: 启用/停止断点
Ctrl+Shift+F9: 删除全部断点
F10: 逐过程
Ctrl+F10: 运行到光标处
F11: 逐语句
编辑快捷键
Shift+Alt+Enter: 切换全屏编辑
Ctrl+B,T / Ctrl+K,K: 切换书签开关
Ctrl+B,N / Ctrl+K,N: 移动到下一书签
Ctrl+B,P: 移动到上一书签
Ctrl+B,C: 清除全部标签
Ctrl+I: 渐进式搜索
Ctrl+Shift+I: 反向渐进式搜索
Ctrl+F: 查找
Ctrl+Shift+F: 在文件中查找
F3: 查找下一个
Shift+F3: 查找上一个
Ctrl+H: 替换
Ctrl+Shift+H: 在文件中替换
Alt+F12: 查找符号(列出所有查找结果)
Ctrl+Shift+V: 剪贴板循环
Ctrl+左右箭头键: 一次可以移动一个单词
Ctrl+上下箭头键: 滚动代码屏幕,但不移动光标位置。
Ctrl+Shift+L: 删除当前行
Ctrl+M,M: 隐藏或展开当前嵌套的折叠状态
Ctrl+M,L: 将所有过程设置为相同的隐藏或展开状态
Ctrl+M,P: 停止大纲显示
Ctrl+E,S: 查看空白
Ctrl+E,W: 自动换行
Ctrl+G: 转到指定行
Shift+Alt+箭头键: 选择矩形文本
Alt+鼠标左按钮: 选择矩形文本
Ctrl+Shift+U: 全部变为大写
Ctrl+U: 全部变为小写
代码快捷键
Ctrl+J / Ctrl+K,L: 列出成员
Ctrl+Shift+空格键 / Ctrl+K,P: 参数信息
Ctrl+K,I: 快速信息
Ctrl+E,C / Ctrl+K,C: 注释选定内容
Ctrl+E,U / Ctrl+K,U: 取消选定注释内容
Ctrl+K,M: 生成方法存根
Ctrl+K,X: 插入代码段
Ctrl+K,S: 插入外侧代码
F12: 转到所调用过程或变量的定义
窗口快捷键
Ctrl+W,W: 浏览器窗口
Ctrl+W,S: 解决方案管理器
Ctrl+W,C: 类视图
Ctrl+W,E: 错误列表
Ctrl+W,O: 输出视图
Ctrl+W,P: 属性窗口
Ctrl+W,T: 任务列表
Ctrl+W,X: 工具箱
Ctrl+W,B: 书签窗口
Ctrl+W,U: 文档大纲
Ctrl+D,B: 断点窗口
Ctrl+D,I: 即时窗口
Ctrl+Tab: 活动窗体切换
Ctrl+Shift+N: 新建项目
Ctrl+Shift+O: 打开项目
Ctrl+Shift+S: 全部保存
Shift+Alt+C: 新建类
Ctrl+Shift+A: 新建项
3、 变量.ToString()
字符型转换 转为字符串
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16进制)
12345.ToString("p"); //生成 1,234,500.00%
1.9 取中文日期显示——年月日时分
string strY=currentTime.ToString("f"); //不显示秒
1.10 取中文日期显示_年月
string strYM=currentTime.ToString("y");
1.11 取中文日期显示_月日
string strMD=currentTime.ToString("m");
1.12 取中文年月日
string strYMD=currentTime.ToString("D");
1.13 取当前时分,格式为:14:24
string strT=currentTime.ToString("t");
1.14 取当前时间,格式为:2003-09-23T14:46:48
string strT=currentTime.ToString("s");
1.15 取当前时间,格式为:2003-09-23 14:48:30Z
string strT=currentTime.ToString("u");
1.16 取当前时间,格式为:2003-09-23 14:48
string strT=currentTime.ToString("g");
1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
string strT=currentTime.ToString("r");
1.18获得当前时间 n 天后的日期时间
DateTime newDay = DateTime.Now.AddDays(100);
字串变量.Replace("子字串","替换为")
字串替换
如:
string str="中国";
str=str.Replace("国","央"); //将国字换为央字
Response.Write(str); //输出结果为“中央”
public class SomeClass { const int DefaultSize=100; public SomeMethod() { } } |
int number;
void MyMethod(int someNumber)
{}
|
interface ImyInterface
{…}
|
public class SomeClass
{
private int m_Number;
}
|
//正确
public class LinkedList<K,T>
{…}
//避免
public class LinkedList<KeyType,DataType>
{….}
|
using System;
using System.Collection.Generic;
using System.ComponentModel;
using System.Data;
using MyCompany;
using MyControls;
|
delegate void SomeDelegate();
public void SomeMethod()
{…}
SomeDelegate someDelegate=SomeMethod;
|
public class MyClass
{
int m_Number;
string m_Name;
public void SomeMethod1();
public void SomeMethod2();
}
|
// In MyClass.cs
public partial class MyClass
{…}
//In MyClass.Designer.cs
public partial class MyClass
{…}
|
public class MyClass
{
public const int DaysInWeek=7;
pubic readonly int Number;
public MyClass(int someValue)
{
Number=someValue;
}
}
|
using System.Diagnostics;
object GetObject()
{…}
object someObject=GetObject();
Debug.assert(someObject!=null);
|
catch(Exception exception)
{
MessageBox.Show(exception.Message);
throw;//或throw exception;
}
|
//正确
public enum Color
{
Red,Green,Blue
}
//避免
public enum Color
{
Red=1,Green=2,Blue=3
}
|
//避免
public enum Color:long
{
Red,Green,Blue
}
|
Bool IsEverythingOK()
{…}
//避免
if(IsEverythingOk())
{…}
//正确
bool ok=IsEverythingOK();
if (ok)
{…}
|
public class MyClass
{}
const int ArraySize=100;
MyClass[] array=new MyClass[ArraySize];
For (int index=0;index<array.Length;index++)
{
array[index]=new MyClass();
}
|
Dog dog=new GermanShepherd();
GermanShepherd shepherd=dog as GermanShepherd;
if (shepherd!=null)
{…}
|
Public class MyPublisher
{
MyDelegate m_SomeEvent;
Public event MyDelegate SomeEvent
{
add
{
m_SomeEvent+=value;
}
remove
{
m_SomeEvent-=value;
}
}
}
|
SomeType obj1;
ImyInterface obj2;
/*Some code to initialize obj1,then:*/
obj2=obj1 as ImyInterface;
if(obj2!=null)
{
obj2.Method1();
}
else
{
//Handle erro in expected interface
}
|
//避免
string name=””;
//正确
string name=String.Empty;
|
int number=SomeMethod();
swith(number)
{
case 1:
trace.WriteLine(“Case 1:”)
break;
case 2:
trace.Writeline(“Case 2:”);
break;
default:
debug.Assert(false);
break;
}
|
//Example of proper use of ‘this’
public class MyClass
{
public MyClass(string message)
{ }
public MyClass():this(“Hello”)
{ }
}
|
//Example of proper use of ‘base’
public class Dog
{
public Dog(string name)
{ }
virtual public void Bark(int howlong)
{ }
}
public class GermanShepherd:Dog
{
public GermanShepherd(string name):base(name)
{ }
override public void Bark(int howLong)
{
base.Bark(howLong)
}
}
|
Int CalcPower(int number,int power)
{
int result=1;
for (int count=1;count<=power;count++)
{
checked
{
result*=number;
}
}
return result;
}
|
public class MyClass
{
[Conditional(“MySpecialCondition”)]
public void MyMethod()
{}
}
|
Public class Customer
{}
//避免:
public interface Ilist<T> where T:Customer
{}
//正确:
public interface IcustomerList:Ilist<Customer>
|
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1476859