namespace Demo
{
public class Test
{
private string scope = "全局变量";
public string getResult()
{
string scope = "局部变量";
// 在这里,this代表Test的实例,所以this.scope指向的是全局变量,scope所访问的是局部变量
return this.scope + "-" + scope;
}
}
class Program
{
static void Main(string[] args)
{
try
{
Test test = new Test();
Console.WriteLine(test.getResult());
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.ReadLine();
}
}
}
namespace Demo
{
public class Test
{
public Test()
{
Console.WriteLine("无参构造函数");
}
// 这里的this()指向的是Test()无参构造函数
// 相当于继承了无参构造函数
public Test(string text) : this()
{
// 程序进来后会先执行Test()无参函数,然后继续往下边执行
Console.WriteLine(text);
Console.WriteLine("有参构造函数");
}
}
class Program
{
static void Main(string[] args)
{
try
{
Test test = new Test("张三");
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
Console.ReadLine();
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有