C#语法(List、方法的调用)
2017-06-16 11:54
288 查看
class GroupSample1
{
// The element type of the data source.
public class Student
{
public string First { get; set; }
public string Last { get; set; }
public int ID { get; set; }
public List<int> Scores;
}
public static List<Student> GetStudents()
{
// Use a collection initializer to create the data source. Note that each element
// in the list contains an inner sequence of scores.
List<Student> students = new List<Student>
{
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 72, 81, 60}},
new Student {First="Claire", Last="O'Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}},
new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {99, 89, 91, 95}},
new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {72, 81, 65, 84}},
new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {97, 89, 85, 82}}
};
return students;
}
}
//C#字符串转数组(循环输出)
string str = "文学笔记|计算机笔记|物流笔记";
string[] sarr = str.Split('|');
foreach (var item in sarr)
{
Response.Write(item + "<br />");
}
//C#字符串数组转字符串
string str = "名字1|代码2|表格3";
string[] sarr = str.Split('|');
string arrStr = string.Join(",", sarr);//数组转成字符串
Response.Write(arrStr);
//类的调用(加static与不加static)
//创建的类
//=C#时间处理
DateTime dt;
System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy/MM/dd";
dt = Convert.ToDateTime("2011/05/26", dtFormat);
Response.Write(dt.ToString("yyyyMMdd"));
//////////////////////////////////////////////////////
基本
一元
乘法
加法
Shift
关系和类型测试
相等
逻辑“与”
逻辑 XOR
逻辑“或”
条件“与”
条件“或”
null 合并
条件运算
赋值或匿名函数
{
// The element type of the data source.
public class Student
{
public string First { get; set; }
public string Last { get; set; }
public int ID { get; set; }
public List<int> Scores;
}
public static List<Student> GetStudents()
{
// Use a collection initializer to create the data source. Note that each element
// in the list contains an inner sequence of scores.
List<Student> students = new List<Student>
{
new Student {First="Svetlana", Last="Omelchenko", ID=111, Scores= new List<int> {97, 72, 81, 60}},
new Student {First="Claire", Last="O'Donnell", ID=112, Scores= new List<int> {75, 84, 91, 39}},
new Student {First="Sven", Last="Mortensen", ID=113, Scores= new List<int> {99, 89, 91, 95}},
new Student {First="Cesar", Last="Garcia", ID=114, Scores= new List<int> {72, 81, 65, 84}},
new Student {First="Debra", Last="Garcia", ID=115, Scores= new List<int> {97, 89, 85, 82}}
};
return students;
}
}
//C#字符串转数组(循环输出)
string str = "文学笔记|计算机笔记|物流笔记";
string[] sarr = str.Split('|');
foreach (var item in sarr)
{
Response.Write(item + "<br />");
}
//C#字符串数组转字符串
string str = "名字1|代码2|表格3";
string[] sarr = str.Split('|');
string arrStr = string.Join(",", sarr);//数组转成字符串
Response.Write(arrStr);
//类的调用(加static与不加static)
//创建的类
//=C#时间处理
DateTime dt;
System.Globalization.DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.ShortDatePattern = "yyyy/MM/dd";
dt = Convert.ToDateTime("2011/05/26", dtFormat);
Response.Write(dt.ToString("yyyyMMdd"));
//////////////////////////////////////////////////////
基本
x.m:成员访问
x(...):方法和委托调用
x[...]:数组和索引器访问
x++:后置递增
x--:后置递减
new T(...):对象和委托创建
new T(...){...}:使用初始值设定项的对象创建
new {...}:匿名对象初始值设定项
new T[...]:数组创建
typeof(T):获取
T的 @System.Type 对象
checked(x):在已检查的上下文中计算表达式
unchecked(x):在未检查的上下文中计算表达式
default(T):获取类型为
T的默认值
delegate {...}:匿名函数(匿名方法)
一元
+x:标识
-x:取反
!x:逻辑取反
~x:按位取反
++x:前置递增
--x:前置递减
(T)x:将
x显式转换成类型
T
await x:异步等待
x完成
乘法
x * y:乘法
x / y:除法
x % y:求余
加法
x + y:加法、字符串串联、委托组合
x – y:减法、委托删除
Shift
x << y:左移位
x >> y:右移位
关系和类型测试
x < y:小于
x > y:大于
x <= y:小于或等于
x >= y:大于或等于
x is T:如果
x是
T,返回
true;否则,返回
false
x as T:返回类型为
T的
x;如果
x的类型不是
T,返回
null
相等
x == y:等于
x != y:不等于
逻辑“与”
x & y:整数型位AND,布尔型逻辑 AND
逻辑 XOR
x ^ y:整数型位 XOR,布尔型逻辑 XOR
逻辑“或”
x | y:整数型位 OR,布尔型逻辑 OR
条件“与”
x && y:仅当
x不是
false时,才计算
y
条件“或”
x || y:仅当
x不是
true时,才计算
y
null 合并
x ?? y:如果
x为 null,计算结果为
y;否则,计算结果为
x
条件运算
x ? y : z:如果
x为
true,计算
y;如果
x为
false,计算
z
赋值或匿名函数
x = y:赋值
x op= y:复合赋值;支持以下运算符
*=
/=
%=
+=
-=
<<=
>>=
&=
^=
|=
(T x) => y:匿名函数(lambda 表达式)
相关文章推荐
- C#在构造函数中调用构造函数的方法(语法)
- Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库 自定义日志记录功能,按日记录,很方便 C#常量和字段以及各种方法的语法总结 类型,对象,线程栈,托管堆在运行时的关系,以及clr如何调用静态方法,实例方法,和虚方法 asp.net webapi 自定义身份验证
- C# 2.0 匿名方法与 Windows Forms 异步调用
- C#调用SQL Server Reports的方法(存储过程)
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- 在c#中调用windows脚本的方法
- C#中同一个类的多个构造方法之间的调用
- 不用AJAX实现前台JS调用后台C#方法(小技巧) (转)
- C#实现动态灵活调用业务方法的机制
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- 在c#中调用windows脚本的方法
- C#动态方法调用
- "C#类中虚方法相互调用的潜在重载错误"相关思考
- 调用C#实现系统功能类的主要方法
- delphi调用C#的web service汉字乱码的解决方法
- 不用AJAX实现前台JS调用后台C#方法(小技巧)
- C#调用DLL方法
- C#实现Web程序调用Windows程序的方法
- javascript调用c#后台代码的方法
- C#.net中web工程中创建用户控件和被调用的方法