c#面向对象
命名空間/程序集:
命名空間是:namespace 后面可以起名字。在上面的是引用:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
用到那個功能就要引用那個using.
如果建立一個新文件夾aaa,并在文件夾中建立一個類,那么要向using中引用才能實(shí)現(xiàn)。
?
訪問修飾符:
public - 公共的
private - 私有的
internal - 默認(rèn)的
protected - 被保護(hù)的
類:
成員變量
private string _name;
屬性
public string name{
get {return _name;}
set{_name = value;}
}
public decimal scoresum():
帶著括號的是方法
比如求和的時候
public decimal scoresum(){
return _cscore+_mscore+_escore;
}
構(gòu)造函數(shù)是默認(rèn)在每個類中都有一個構(gòu)造函數(shù),構(gòu)造函數(shù)中沒有返回類型,類名叫什么,構(gòu)造函數(shù)叫什么:
默認(rèn)隱藏。
public ?student(){
}
實(shí)例化就是執(zhí)行構(gòu)造函數(shù)的一個過程。
?其中靜態(tài)表示為:
public static decimal jiafa (decimal a , decimal b){
return a+b
}
靜態(tài)類不需要實(shí)例化,直接通過類名點(diǎn)出來:
decimal aaa =100;
decimal bbb=60;
decimal ccc = mamath .jiafa(aaa,bbb);
console.writeLine(ccc);
轉(zhuǎn)載于:https://www.cnblogs.com/qwer123666/p/7097455.html
總結(jié)
- 上一篇: 一代性价比之王再进化!moto S30
- 下一篇: “复刻”小米12!Redmi K50至尊