追着嘟嘟学c#系列基础第六篇-----c#方法【蓝鸥出品】

来源:互联网 发布:linux less 退出 编辑:程序博客网 时间:2024/05/17 09:19

c#中只有类中可以定义方法
 访问说明符 返回值类型 方法名(c#中方法名字大写){语句;......; return 返回值}
  void 表示没有返回值
                   publicvoidRun(intl,strings){
                             
Console.WriteLine ("往前开{ 0}米",l);
                             
Console.WriteLine (s);
                   }
                   
publicint  Add(inta,intb){
                             
intc = a + b;
                             
returnc;
                   }
访问私有成员的方法
 privatestringname="wangwang";
     //      Get方法
 publicstringGetName(){
            returnname;
    }
  //      Set方法
   publicvoid  SetName(stringnewName){
              name = newName;
     }
调用方法:对象.(参数);
                             c.Run (10,"sdasd");
                             c.Add (
5,6);
                             
inti = c.Add (5,6);
                             c.SetName ("xiaowang");
链接:http://edu.csdn.net/course/detail/2050/31828?auto_start=1

0 0
原创粉丝点击