c#怎样清屏
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespa...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StatementExample
{
public class Child
{
private int age;
private string name;
public Child()
{
name = "none";
}
public Child(string name, int age)
{
this.name = name;
this.age = age;
}
public void PrintChild()
{
Console.WriteLine("{0},{1} years old.", name, age);
}
}
class Program
{
static void Main(string[] args)
{
Console.Clear();
Child child1 = new Child("Zhang San", 11);
Child child2 = new Child("Li Si", 10);
Child child3 = new Child();
Console.Write("Child #1: ");
child1.PrintChild();
Console.Write("Child #2: ");
child2.PrintChild();
Console.Write("Child #3: ");
child3.PrintChild();
Console.ReadLine();
}
}
}
上述代码中,第一次运行后我把Main()中对定义的三个类做注释处理如下:
//Child child1 = new Child("Zhang San", 11);
//Child child2 = new Child("Li Si", 10);
//Child child3 = new Child();
但是,第二次运行该程序时,依然显示:
Child #1: Zhang San,11 years old.
Child #2: Li Si,10 years old.
Child #3: none,0 years old. 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace StatementExample
{
public class Child
{
private int age;
private string name;
public Child()
{
name = "none";
}
public Child(string name, int age)
{
this.name = name;
this.age = age;
}
public void PrintChild()
{
Console.WriteLine("{0},{1} years old.", name, age);
}
}
class Program
{
static void Main(string[] args)
{
Console.Clear();
Child child1 = new Child("Zhang San", 11);
Child child2 = new Child("Li Si", 10);
Child child3 = new Child();
Console.Write("Child #1: ");
child1.PrintChild();
Console.Write("Child #2: ");
child2.PrintChild();
Console.Write("Child #3: ");
child3.PrintChild();
Console.ReadLine();
}
}
}
上述代码中,第一次运行后我把Main()中对定义的三个类做注释处理如下:
//Child child1 = new Child("Zhang San", 11);
//Child child2 = new Child("Li Si", 10);
//Child child3 = new Child();
但是,第二次运行该程序时,依然显示:
Child #1: Zhang San,11 years old.
Child #2: Li Si,10 years old.
Child #3: none,0 years old. 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询