C#语法(List、方法的调用)
来源:互联网 发布:汉译英好用的翻译软件 编辑:程序博客网 时间:2024/05/19 20:45
{
// 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#语法(List、方法的调用)
- C#方法的调用
- 【C#语法】C#中调用C++编写的dll
- C#调用Bat的方法。
- C#调用C++的方法
- C#简单的方法调用
- JS调用C#的方法
- .Net C#语法 方法的重载
- C# 冷门的语法和属性方法
- c# List的好用的方法
- c#范型List的Sort方法详解
- C# 中 List的好方法
- c#范型List的Sort方法详解
- c#范型List的Sort方法详解
- c#范型List的Sort方法详解
- C# List Sort的三种方法
- C# 去掉List重复元素的方法
- C# 去掉List重复元素的方法
- Unity Resource文件夹的使用
- 笑谈java并发编程七之ExecutorService
- SEO--nofollow标签
- 职责链模式(Chain of Responsibility)(对象行为型)
- 《Effective Modern C++》读书笔记(3) -- 明白decltype(understand decltype)
- C#语法(List、方法的调用)
- android 模拟点击按键功能(android 4.4)
- Spring dateSource简要配置及解释
- SQL Server表分区
- 死锁
- Ansj5.1.1 过滤停用词的方法
- 半平面交
- linux操作系统基础学习笔记
- 云服务器 centos mysql搭建