• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C#Basic

原作者: [db:作者] 来自: [db:来源] 收藏 邀请
变量声明
1int x;
2String s;
3String s1, s2;
4Object o;
5Object obj = new Object();
6public String name;

语句:

1Response.Write("foo");

注释
1// This is a comment
2
3*/

访问索引属性:
1String s = Request.QueryString["Name"];
2String value = Request.Cookies["key"];

声明索引属性
1// Default Indexed Property
2}

声明简单属性
 1}

声明和使用枚举
 1// Declare the Enumeration
 2 Small;

枚举集合
1}

声明和使用方法
 1// Declare a void return function
 2);

自定义属性
1// Stand-alone attribute
2[STAThread]
3
4// Attribute with parameters
5[DllImport("ADVAPI32.DLL")]
6
7// Attribute with named parameters
8[DllImport("KERNEL32.DLL",CharSet=CharSet.Auto)]

数组
1String[] a = new String[3];
2a[0= "1";
3a[1= "2";
4a[2= "3";
5
6String[][] a = new String[3][3];
7a[0][0= "1";
8a[1][0= "2";
9a[2][0= "3";

初始化
1String s = "Hello World";
2int i = 1;
3;

If 语句
1}

Case 语句
 1}

For 循环
1for (int i=0; i<3; i++)
2  a(i) = "test";

While 循环
1int i = 0;
2}

异常处理
1}

字符串连接
 1// Using Strings
 2String s1;
 3String s2 = "hello";
 4s2 += " world";
 5s1 = s2 + " !!!";
 6
 7// Using StringBuilder class for performance
 8StringBuilder s3 = new StringBuilder();
 9s3.Append("hello");
10s3.Append(" world");
11s3.Append(" !!!");

事件处理程序委托
1void MyButton_Click(Object sender,
2}

声明事件:
1// Create a public event
2public event EventHandler MyEvent;
3
4// Create a method for firing the event
5}

向事件添加事件处理程序或从事件移除事件处理程序:
1Control.Change += new EventHandler(this.ChangeEventHandler);
2Control.Change -= new EventHandler(this.ChangeEventHandler);

强制类型转换:
1MyObject obj = (MyObject)Session["Some Value"];
2IMyObject iObj = obj;

转换:
1int i = 3;
2String s = i.ToString();
3double d = Double.Parse(s);

带继承的类定义:
 1using System;
 2
 3 library.cs

实现接口:
1}

带 Main 方法的类定义:
 1using System;
 2
 3 csc /out:consolecs.exe /t:exe console.cs

标准模块:
 1using System;
 2
 3 csc /out:consolecs.exe /t:exe console.cs

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C#语言之“中英文混合字符串对齐”的方法发布时间:2022-07-10
下一篇:
C#多语言实现(三)发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap