您的位置:首页 > 其它

The C sharp basic knowledge about

2009-02-24 12:02 162 查看
*声明和使用变量
-------------------------
const double PAI = 3.141592;//定义圆周率
-------------------------
int x, y ;
int z=0;
-------------------------
class test  //类 --可自定义
{
private int x; //定义局部变量   局部变量不能被类外部程序引用
public int x; //定义全局变量
}

test test1 = new test();// 初始化test类 test1为上test的类型
// 引用时可以直接使用,例如 test1.x  为test类中x的值
-------------------------

*字符串运算符
-------------------------
[ ]  索引 从0 开始
-------------------------
staring str1 = "hello";

str1+str2; //+连接字符串
-------------------------
string[] strArray ={"this","is","test"};
strArray[0]; //输出数组中的第一个值  this
strArray[2]; //输出数组中的第三个值 test
-------------------------
* 赋值运算符
-------------------------
int x =10;
string str ="字符";
StringBuilder str1 = new StringBuilder();// 类赋值
int[] arr = {1,2,3,4} ;// 数组赋值
x+ =arr[1];
-------------------------

* 逻辑运算符
-------------------------
&& 与         // if ( x== 5 && y = 5 )
|| 或 // if ( x == 50 || y =  50 )
!  非 // if ( !(y == 5) )
-------------------------

* 流程控制
-------------------------
if 语句

if (条件)
{   }
else
{   }
-------------------------
判断多个条件
if ()
{}
esle if()
{}
else if()
{}
else
{}
-------------------------

switch 分支

switch (条件) //当下面的条件与值相等,即执行相应case
{
case 值:
.....
break;
case  值:
break;
default:
.....
break;
}
-------------------------

while(条件)
{
.......
}
-------------------------
for(int i=10;i>3;i--)
{
Console.WriteLine("当前变量值为:{0}",i);
}

-------------------------

break /  continue 控制循环

break 跳出循环体
continue 跳出本次循环

-------------------------

#define 条件编译

#define 定义标识符
#undef 取消定义标识符

#if DEBUG //判断是否已经定义标识符
console.writeline("........");
#endif
-------------------------

命名空间

namespace ConsoleApplivation1
{
namesapce myspace
{
class Class1
{
public void test()
{
Console.WriteLine("a");
}
}
}
}
--------------------------
调用类
static void Main(string[] args)
{
myspace.Class1 mycls = new ConsoleApplication1.myspace.Class1();
mycls.test();
}
--------------------------

--------------------------------------------------------------------------------------
控件

ContextMenuStrip 右击鼠标弹出快捷菜单
MenuStrip 菜单
StatusStrip 信息提示栏‘状态栏
ToolStrip 工具栏 按钮
ToolStripContainer 容器 用于装载控件
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息