欢迎光临
我们一直在努力

C#学习笔记之一(basic, class, function,array, collection interface)-.NET教程,C#语言

建站超值云服务器,限时71元/月

最近学习了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, ib {}

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » C#学习笔记之一(basic, class, function,array, collection interface)-.NET教程,C#语言
分享到: 更多 (0)

相关推荐

  • 暂无文章