C# 基础(更新中)
Data Structure
There're two types of variables in C#, reference type and value type.
Enum:
enum Color{
Red=0,
Green=1
}
//equals to
enum Color{
Red,//start from 0 as default
Green
}
int to enum:(Color)val
Arrays and Collections
Array
declare array:
new int[10]
new int[10]{xx,xx.....};
new int[]{aa,aa};
Collection
List<string> theList=new List<string>();//can use value type here, not only reference type
theList.Count;//size of the list
class
when calling same name class with different namespace, it will use class of same namespace first, then System
namespace.
fields and properties
- can't use var to declare fields like
var count=0
,must useint count=0
const
is static, so we can't use them together likepublic static const int count=0
- rules of naming fields and property: first letter with uppercase is public, first letter with lowercase is private.
Auto-implemented property: remove their private fields.
initiate with default: public MyClass val {get;set;} = new MyClass();
anonymous type
for the cases:
- only use in one function and not need for other functions
- only exists for only short time, and will be stored to other places
var val=new {name='Alex', age=12};
Extensions
class TheExtensionClass{
public int toInt(this string value){
return int.Parse(value);
}
}
//so that the function can be called on string
str.toInt();
function
out, in and ref
if use out/in/ref
for value type variable, then it will convert to reference type.
must initiate out
variable in the function before use it.
default parameter and named parameter
Default parameter
- must declared after non-default parameter
- if we don't want to give value to the first default parameter but want to give the second default parameter, we can't do this without named parameter
Named parameter:
can call the function and break the sequence of parameters, especially for default parameter
special function:lambda
for the cases:
- short function
var res=theList.Find(MyFunc);
boolean MyFunc(Student aStudent){
return studentName="abc";
}
theList.Find(student=>{
return studentName="abc";
});
theList.Find(student=> studentName="abc");
Event and asynchronous programming
Event
for the cases:
when executing monitor function, it will automatically execute the monitored function
- declare Action variable in class A:
Action action
- binding the action variable to f2 (monitored function) of class B:
action+=f2
- trigger the event: in f3(monitor function) call the action with
action();
### asynchronous programming
like event
RequestSupport(CallBackFunc)
Exception and log
Exception
try{
}catch{
}
try{
}catch(FormatException){
}
try{
}catch(FormatException e){
print e;
print e.Message;
}
Log
C# 基础(更新中)的更多相关文章
- 第一章:大数据 の Linux 基础 [更新中]
本课主题 Linux 休系结构图 Linux 系统启动的顺序 Linux 查看内存和 CPU 指令 环境变量加载顺序 Linux 内存结构 Linux 休系结构图 Linux 大致分为三个层次,第一层 ...
- Unity---UGUI入门基础---更新中
目录 1.UGUI介绍 2.UGUI基础 2.1 Canvas---画布 2.2 Text控件 2.3 Image控件 2.4 RawImage控件 2.5 Button控件 2.6 Toggle控件 ...
- Pig基础学习【持续更新中】
*本文参考了Pig官方文档以及已有的一些博客,并加上了自己的一些知识性的理解.目前正在持续更新中.* Pig作为一种处理大规模数据的高级查询语言,底层是转换成MapReduce实现的,可以作为MapR ...
- Pig语言基础-【持续更新中】
***本文参考了Pig官方文档以及已有的一些博客,并加上了自己的一些知识性的理解.目前正在持续更新中.*** Pig作为一种处理大规模数据的高级查询语言,底层是转换成MapReduce实现的, ...
- java视频教程 Java自学视频整理(持续更新中...)
视频教程,马士兵java视频教程,java视频 1.Java基础视频 <张孝祥JAVA视频教程>完整版[RMVB](东西网) 历经5年锤炼(史上最适合初学者入门的Java基础视频)(传智播 ...
- Android开发面试经——4.常见Android进阶笔试题(更新中...)
Android开发(29) 版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...
- 《WCF技术剖析》博文系列汇总[持续更新中]
原文:<WCF技术剖析>博文系列汇总[持续更新中] 近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析(卷1)>的写作,一直无暇管理自己的Blog.在<WCF技术剖 ...
- 【前端】Util.js-ES6实现的常用100多个javaScript简短函数封装合集(持续更新中)
Util.js (持续更新中...) 项目地址: https://github.com/dragonir/Util.js 项目描述 Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包 ...
- Linux 系统化学习系列文章总目录(持续更新中)
本页内容都是本人系统化学习Linux 时整理出来的.这些文章中,绝大多数命令类内容都是翻译.整理man或info文档总结出来的,所以相对都比较完整. 本人的写作方式.风格也可能会让朋友一看就恶心到直接 ...
随机推荐
- Redis学习小结
在7月中旬,我成功入职实习,通过进入公司,认识到了个人与企业巨大的差距,首先就是对于中间件的使用,ElasticSearch.Redis.Kafka等等,都是听过却从未使用过的,然而在任务下达之后,激 ...
- 巩固javaweb第十四天
巩固内容: 单行文本框: 单行文本框的基本语法格式如下: < input type="text" name="输入信息的字" value=" ...
- 日常Java 2021/9/21
将Java数组中的元素前后反转.题目要求:已知一个数组arr = {11,12,13,14,15}用程序实现把该数组中的元素值交换,交换后的数组arr = { 15,14,13,12,11},并输出交 ...
- 爬虫系列:使用 MySQL 存储数据
上一篇文章我们讲解了爬虫如何存储 CSV 文件,这篇文章,我们讲解如何将采集到的数据保存到 MySQL 数据库中. MySQL 是目前最受欢迎的开源关系型数据库管理系统.一个开源项目具有如此之竞争力实 ...
- iOS 客户端获取七牛上传token
一.官方参考文档: 1.上传策略http://developer.qiniu.com/article/developer/security/put-policy.html 2.上传凭证(即uptoke ...
- YYYY-MM-DD引发的问题
yyyy 和 YYYY 用YYYY格式化代码 2019-12-31 转 YYYY/MM/dd 格式: 2020/12/31 2020-01-01 转 YYYY/MM/dd 格式: 2020/01/01 ...
- Spring Boot下使用JSP页面
一.创建webapp目录 在src/main下创建webapp目录,用于存放jsp文件.这就是一个普通的目录,无需执行Mark Directory As 二.创建jsp 1.指定web资源目录 在sp ...
- 通过Jedis操作Redis
package com.yh; import org.junit.After; import org.junit.Before; import org.junit.Test; import redis ...
- C#ADO.NET技术总结
[ADO.NET的主要组件-..NET framework数据提供程序和DataSet(数据集)] 一.DataSet数据集负责对数据库执行命令. 二.NET framework数据提供程序的四个核心 ...
- 象群游牧算法-Matlab
1. 适应度函数: function z=chaffer(x)%chaffer函数x=(0...0) f(x)=0 x[-10,10]%%没测 n=10; s1=0; for i=1:n s1=s1+ ...