惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Stack Overflow Blog
Stack Overflow Blog
量子位
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
美团技术团队
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
Recent Announcements
Recent Announcements
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
酷 壳 – CoolShell
酷 壳 – CoolShell
J
Java Code Geeks
V
V2EX
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
博客园 - Franky
爱范儿
爱范儿
T
Tailwind CSS Blog
A
About on SuperTechFans
Google DeepMind News
Google DeepMind News
博客园_首页
B
Blog RSS Feed
博客园 - 司徒正美
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - Fanny123

LeetCode最大数字范围的整数之和 LeetCode统计好子数组 LeetCode边界与内部和相等的稳定子数组 三段式数组II 变为活跃状态的最小时间 平衡装运的最大数量 三段式数组 I 相邻字符串之间的最长公共前缀 分割字符串 找出数组中的所有 K 近邻下标 使叶子路径成本相等的最小增量 硬币面值还原 检查元素频次是否为质数 等积子集的划分方案 统计一个数组中好对子的数目 LeetCode 1482. 制作 m 束花所需的最少天数 圆形靶内的最大飞镖数量 丑数 验证栈序列 BST的中序后继
C# 基础(更新中)
Fanny123 · 2020-05-31 · via 博客园 - Fanny123

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