c#面向对象

命名空间/程序集:

命名空间是:namespace 后面可以起名字。在上面的是引用:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

用到那个功能就要引用那个using.

如果建立一个新文件夹aaa,并在文件夹中建立一个类,那么要向using中引用才能实现。

 

访问修饰符:
public - 公共的
private - 私有的

internal - 默认的
protected - 被保护的

类:

成员变量

private string _name;

属性

public string name{

get {return _name;}

set{_name = value;}

}

public decimal scoresum():

带着括号的是方法

比如求和的时候

public decimal scoresum(){

return _cscore+_mscore+_escore;

}

构造函数是默认在每个类中都有一个构造函数,构造函数中没有返回类型,类名叫什么,构造函数叫什么:

默认隐藏。

public  student(){

}

实例化就是执行构造函数的一个过程。

 其中静态表示为:

public static decimal jiafa (decimal a , decimal b){

return a+b

}

静态类不需要实例化,直接通过类名点出来:

decimal aaa =100;

decimal bbb=60;

decimal ccc = mamath .jiafa(aaa,bbb);

console.writeLine(ccc);

posted @ 2017-06-30 09:52  小伙子很浪  阅读(159)  评论(0编辑  收藏  举报