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 观察局部变量的值和变化