国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#學習筆記之一(basic, class, function,array, collection

2024-07-21 02:27:58
字體:
來源:轉載
供稿:網友
最近學習了c#程序設計的課程, 現在將筆記總結如下, 沒有系統整理,都是課上記得notes, 后面幾部分以程序居多,因為這些筆記沒有做過整理,所以很多code沒有詳細的注釋,如果有時間的話,我會對筆記做系統的整理,還有這里沒有提及基本的語法介紹,望大家諒解:

basic:
//利用out, 不用給i,j assign初始值
int i,j;
f(out i, out j) {}
//using, 括號外自動destroy對象
using (font thefont == new font("ariel", 10.0f)){}
//constants
const int i = 32;
//enumeration
enum e {a=5,b=8}
int i = (int) e.a;
//turn buff data to string
encoding.ascii.getstring(buff, 0, bytesread)
// read data
string s = console.readline()
int j= convert.toint32(s);
//get textbox value and convert to double
double left = double.parse(textbox1.text);
application.doevent(); //this will let app deal with event
array:
a[] a = new a[5]; // a[0]to a[5] is null
int[] arr = new int[2] {1,2}
int[] arr = {2,3,4,5}
foreach(a a in arr_a) {}
for(int i=0; i<arr.length; i++) {}
//rectangular arrays
int[,] rectarray = new int[4,5]
int[,] arr = {{1,2,3,4},{1,2,3,4}{1,2,3,4}}; //init
//jagged array, 數組中包含數組,各維不等長
// ja[0].length is length of ja[0]
int [][] ja = new int[4][];
//using params transfer a array to a function
//using f(1,2,3,4) to call the function
f(params int[] values){
foreach (int[] a in values) {}
}
collection interface:
indexers:
//define a indexers
public myclass this[int offset] {get{};set{}}
//call it
employee joe = bostonoffice["joe"];
ienumerable:
//return a ienumerator object
getenumerator()
ienumerator:
reset(){}
current(){}
movenext(){}
icomparable:
//class inherit icomparable interface
//implement compareto() method
compareto()
arraylists:
count get number of elements
add() add an object
clear() remove all objects
reverse() reverse order of elements
sort() sort the elements
function:
//default by value
f(int x){}
//by reference
f(ref int x){}
class:
//存取:
public, private, protected, internal, protected internal
this, static //static member must be init in class
//繼承
class a: b {}
//多態
virtual,override
//init對象
employee emp1 = new employee();

//先隱式轉換3為roman
roman r4 = r1 + 3;
//先顯式轉換7.5為roman
roman r5 = r1 +(roman)7.5;

// 運算符重載,先返回int, 然后用隱式轉換
public static roman operator+ (roman l, roman r)
{
return (l.val+r.val);
}
//顯式轉換
public static explicit operator roman(float val)
{
return new roman(val);
}
//隱式轉換
public static implicit operator roman(int val)
{
return new roman(val);
}
//properties, 注意大小寫
public int age {
get {return age;}
set {age = value;}
}

//interface
//interface methods must be implement in class
public interface ia {}
//is 測試類是否從接口繼承
if (a is ia) {ia c = (ia) a; }
//as 測試類是否從接口繼承
ia c = a as ia;
if (c != null) {}
//interface properties
pubiic interface iaa: ia
{
float f{get;set;}
}
//mutiface interface inheritance
public class c: ia,


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 微山县| 博罗县| 镇远县| 灯塔市| 黎川县| 泰来县| 博客| 威海市| 青海省| 扎兰屯市| 宜春市| 北海市| 股票| 徐州市| 周宁县| 阳曲县| 阳高县| 青岛市| 车险| 崇礼县| 石阡县| 定陶县| 武邑县| 木兰县| 澄迈县| 集贤县| 甘南县| 虹口区| 黄山市| 湖口县| 盐边县| 长沙县| 鄂州市| 高青县| 通渭县| 丰城市| 博爱县| 福泉市| 曲松县| 永寿县| 二手房|