问题描述:
c#中this的用法
using System;
namespace CallConstructor
{
public class Car
{
int petalCount = 0;
String s = "null";
Car(int petals)
{
petalCount = petals;
Console.WriteLine("Constructor w/int arg only,petalCount = " + petalCount);
}
Car(String s,int petals)
:this(petals)
{
this.s = s;
Console.WriteLine("String & int args");
}
Car()
:this("hi",47)
{
Console.WriteLine("default constructor");
}
public static void Main()
{
Car x = new Car();
Console.Read();
}
}
}
能帮我解释一下这段代码中几个this的意思吗?
using System;
namespace CallConstructor
{
public class Car
{
int petalCount = 0;
String s = "null";
Car(int petals)
{
petalCount = petals;
Console.WriteLine("Constructor w/int arg only,petalCount = " + petalCount);
}
Car(String s,int petals)
:this(petals)
{
this.s = s;
Console.WriteLine("String & int args");
}
Car()
:this("hi",47)
{
Console.WriteLine("default constructor");
}
public static void Main()
{
Car x = new Car();
Console.Read();
}
}
}
能帮我解释一下这段代码中几个this的意思吗?
问题解答:
我来补答展开全文阅读