GetHashCode方法
用于分辨不同的对象
Student stu = new Student();
Console.WriteLine(stu.GetHashCode());
Student st2 = new Student();
Console.WriteLine(st2.GetHashCode());
传值参数
- 值类型
- 引用类型
引用参数
- 定义:使用
ref
修饰符声明的形参 - 特征:不会创建新的存储位置
- 副作用:改变实际参数的值
class Program
{
static void Main(string[] args)
{
int y = 1;
SideEffect(ref y);
Console.WriteLine(y);
}
static void SideEffect(ref int x)
{
x = x + 100;
}
}
输出参数
- 定义:使用out关键字进行修饰的参数
- 特征:输出参数并不创建变量的副本,方法体内必须要有对输出变量赋值的操作
- 副作用(side-effect):通过参数向外输出值
- 值类型的输出参数
class Program
{
static void Main(string[] args)
{
double x = 0;
bool b = DoubleParser.TryParse("123", out x);
if