在此示例中,我初始化了一个变量整数并将整数值传递给参数化构造函数,然后我声明了一个实例方法,我想在其中打印字符串 vale,最后我在主程序中调用该方法。bur 当我打印它的值时它显示我 NULL 值,为什么?
class CPrint
{
int i = 100;
string sToPrint;
// here Initialize a default Constructor.
public CPrint() { }
//public CPrinter() : this("Default Constructor Value") {}
// here defining a custom constructor which take one parameter of string value
public CPrint(string s)
{
sToPrint = s;
}
// here defining a custom constructor which take one parameter of integer value
public CPrint(int i)
{
sToPrint = Convert.ToString(i);
}
// instance method
public void PrintString()
{
Console.WriteLine("I have just printed ...{0}", sToPrint);
}
}
class Program
{
static void Main(string[] args)
{
CPrint p = new CPrint();
p.PrintString();
Console.ReadLine();
}
}