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

  1. can't use var to declare fields like var count=0,must use int count=0
  2. const is static, so we can't use them together like public static const int count=0
  3. 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

  1. declare Action variable in class A:Action action
  2. binding the action variable to f2 (monitored function) of class B:action+=f2
  3. 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# 基础(更新中)的更多相关文章

  1. 第一章:大数据 の Linux 基础 [更新中]

    本课主题 Linux 休系结构图 Linux 系统启动的顺序 Linux 查看内存和 CPU 指令 环境变量加载顺序 Linux 内存结构 Linux 休系结构图 Linux 大致分为三个层次,第一层 ...

  2. Unity---UGUI入门基础---更新中

    目录 1.UGUI介绍 2.UGUI基础 2.1 Canvas---画布 2.2 Text控件 2.3 Image控件 2.4 RawImage控件 2.5 Button控件 2.6 Toggle控件 ...

  3. Pig基础学习【持续更新中】

    *本文参考了Pig官方文档以及已有的一些博客,并加上了自己的一些知识性的理解.目前正在持续更新中.* Pig作为一种处理大规模数据的高级查询语言,底层是转换成MapReduce实现的,可以作为MapR ...

  4. Pig语言基础-【持续更新中】

      ***本文参考了Pig官方文档以及已有的一些博客,并加上了自己的一些知识性的理解.目前正在持续更新中.***   Pig作为一种处理大规模数据的高级查询语言,底层是转换成MapReduce实现的, ...

  5. java视频教程 Java自学视频整理(持续更新中...)

    视频教程,马士兵java视频教程,java视频 1.Java基础视频 <张孝祥JAVA视频教程>完整版[RMVB](东西网) 历经5年锤炼(史上最适合初学者入门的Java基础视频)(传智播 ...

  6. Android开发面试经——4.常见Android进阶笔试题(更新中...)

      Android开发(29)  版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...

  7. 《WCF技术剖析》博文系列汇总[持续更新中]

    原文:<WCF技术剖析>博文系列汇总[持续更新中] 近半年以来,一直忙于我的第一本WCF专著<WCF技术剖析(卷1)>的写作,一直无暇管理自己的Blog.在<WCF技术剖 ...

  8. 【前端】Util.js-ES6实现的常用100多个javaScript简短函数封装合集(持续更新中)

    Util.js (持续更新中...) 项目地址: https://github.com/dragonir/Util.js 项目描述 Util.js 是对常用函数的封装,方便在实际项目中使用,主要内容包 ...

  9. Linux 系统化学习系列文章总目录(持续更新中)

    本页内容都是本人系统化学习Linux 时整理出来的.这些文章中,绝大多数命令类内容都是翻译.整理man或info文档总结出来的,所以相对都比较完整. 本人的写作方式.风格也可能会让朋友一看就恶心到直接 ...

随机推荐

  1. RabbitMQ消息中介之Python使用

    本文介绍RabbitMQ在python下的基本使用 1. RabbitMQ安装,安装RabbitMQ需要预安装erlang语言,Windows直接下载双击安装即可 RabbitMQ下载地址:http: ...

  2. 31-Longest Common Prefix

    Longest Common Prefix My Submissions Difficulty: Easy Write a function to find the longest common pr ...

  3. Excel-计算年龄、工龄 datedif()

    函数名称:DATEDIF 主要功能:计算返回两个日期参数的差值. 使用格式:=DATEDIF(date1,date2,"y").=DATEDIF(date1,date2," ...

  4. 码上来战!探索“智”感生活,HMS Core线上Codelabs挑战赛第4期开始!

    HMS Core线上Codelabs挑战赛第4期正式开始!我们向所有实践力超强.创新力满满的开发者发出邀请,用你的超级"码"力,解锁更多应用价值! 生活里,我们被手机"秒 ...

  5. PowerToys插件扩展(类似Alfred)

    在mac系统除了自带的Spotlight还有一个很好用的工具叫Alfred image 在windows系统也有一个很好用的工具叫PowerToys,是微软的一个开源项目 image https:// ...

  6. 位运算符在JS中的妙用

    正文 位运算 JavaScript 中最臭名昭著的 Bug 就是 0.1 + 0.2 !== 0.3,因为精度的问题,导致所有的浮点运算都是不安全的,具体原因可详见<0.1 + 0.2不等于0. ...

  7. 【swift】用Xib实现自定义警告框(Alert)(安卓叫法:Dialog对话框)

    在写这篇博客前,先感谢两篇博客 [如何自定义的思路]:https://www.cnblogs.com/apprendre-10-28/p/10507794.html [如何绑定Xib并且使用]:htt ...

  8. 最新的Android Sdk 使用Ant多渠道批量打包

    实例工程.所需的文件都在最后的附件中.    今天花费了几个小时,参考网上的资料,期间遇到了好几个问题, 终于实现了使用Ant批量多渠道打包,现在,梳理一下思路,总结使用Ant批量多渠道打包的方法:1 ...

  9. 修改页面.JSP

    <%@ page contentType="text/html;charset=UTF-8" language="java" %><%@tag ...

  10. 设计模式和java实现

    三种工厂模式:https://www.cnblogs.com/toutou/p/4899388.html 适配器模式:https://www.cnblogs.com/V1haoge/p/6479118 ...