刘铁猛C#语言入门详解——学习笔记009

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Student stu = new Student(1,"name");
            Console.WriteLine(stu.ID);
            Console.WriteLine(stu.Name);
            Console.WriteLine("++++++++++++++++++++++");
            Student stu2 = new Student();
            Console.WriteLine(stu2.ID);
            Console.WriteLine(stu2.Name);
        }
    }
   class Student
   {
        /*   修改默认构造器
         *   public Student() 
                {
                    this.ID = 1;
                    this.Name = "name";
                }*/
        //创建带参数的构造器
        public Student(int initID, string initName)
        {
            this.ID = initID;
            this.Name = initName;
        }
        public Student ()
        {
            this.ID = 2;
            this.Name = "lys";
        }
        public int ID;
        public string Name;
   }
}

构造器
方法的重载
debug

构造器,特殊的函数 没有返回值类型
默认构造器
强制创造时带着id
ctor 两下tab自动构造框架
面试问题
调用带参数的构造器内部的过程:
student STU = NEW student(1,"name")
string 类型是一个引用变量,需要再堆上再开辟地址,起始地址是40000015,可能出现两次内存的转存


方法的重载
方法的签名由方法的名称、形参个数和每一个形参类型和种类组成,不包括返回类型
ref int a,int b 
out int a,int b
参数的种类构成方法的签名

对方法进行debug是非常重要的技能
stepinto step over step out
f11 shift f11
 

  

using System;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            Calculate c = new Calculate();

            //double result = Calculate.GetArea(4);
            //double ClinderVolume = Calculate.GetClinderVolume(3, 4);
            double ConeVolume = Calculate.GetConeVolume(3, 4);
            //Console.WriteLine(result );
            Console.WriteLine(ConeVolume);
            //Console.WriteLine(ClinderVolume);

        }
        class Calculate
        {
            public static double GetArea(double r)
            {
                return Math.PI * r * r;

            }
            public static double GetClinderVolume(double r,double h)
            {
                return GetArea(r) * h;
            }
            public static double GetConeVolume(double r,double h)
            {
               double CV =  GetArea(r) * h;
               return CV / 3;
            }
        }
    }
    
}

 

 F11debug

shift+f11可以直接跳转被调用方法的位置,比用call stack上点击再加断点 更方便

stack frame栈的调用顺序
主调者,背调者 变量压栈归主调用者管,谁调用归谁管
local 观察局部变量的值和变化 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值