public void Information(string strName, int intAge) { Console.WriteLine("输入名字或年龄"); \\增加这一行就知道了 Name=Console.ReadLine(); Age=Console.ReadLine(); Console.WriteLine(Name,Age);}
using System; class Employee {string Name; string Age; public void Information() {Console.WriteLine("李克勤");} public void Information(string strName, int intAge) { Name=Console.ReadLine(); Age=Console.ReadLine(); //Console.WriteLine(Name,Age); 改为Console.WriteLine(Name+" "+ Age.ToString());}static void Main() { Employee emp=new Employee(); emp.Information("李白",800);emp.Information(); Console.WriteLine(); } }
加句: System.Console.Read();
using System; class Employee {string Name; string Age; public void Information() {Console.WriteLine("李克勤");} public void Information2(/*string strName, int intAge*/) { Console.WriteLine("please type new employee's name :"); this.Name=Console.ReadLine(); Console.WriteLine("please type new employee's age:"); this.Age=Console.ReadLine(); Console.WriteLine("the new employee's name:{0}:",this.Name); Console.WriteLine("the new employee's arg:{0}:",this.Age);} 原程序升级1.0
using System; class Employee {string Name; string Age; public void Information() {Console.WriteLine("李克勤");} public void Information2(/*string strName, int intAge*/) { Console.WriteLine("please type new employee's name :"); this.Name=Console.ReadLine(); Console.WriteLine("please type new employee's age:"); this.Age=Console.ReadLine(); Console.WriteLine("the new employee's name:{0}:",this.Name); Console.WriteLine("the new employee's arg:{0}:",this.Age);}static void Main(/*string[] args*/) { Employee emp=new Employee(); emp.Information2(/*"李白",800*/);emp.Information(); } } 应该是这个,谢谢你的学习素材
public void Information(string strName, int intAge) { Name=Console.ReadLine(); Age=Console.ReadLine(); Console.WriteLine(Name,Age); } 应该是这个函数错误,因为此函数的两个参数在函数中你根本没有用过,而你用了类中的两个相关的属性,因此在后面的emp.Information("李白",800)中“李白”和“800”就无法显示了,而你在实例类也也没有对类的两个属性进行初始化,所以当然为空了。 此函数应改为: public void Information(string strName, int intAge) { strName=Console.ReadLine(); strAge=Console.ReadLine(); Console.WriteLine(Name,Age); }
public void Information(string strName, int intAge) { strName=Console.ReadLine(); strAge=Console.ReadLine(); Console.WriteLine(atrName,strAge); }
{
Console.WriteLine("输入名字或年龄"); \\增加这一行就知道了
Name=Console.ReadLine();
Age=Console.ReadLine();
Console.WriteLine(Name,Age);}
class Employee
{string Name;
string Age;
public void Information()
{Console.WriteLine("李克勤");}
public void Information(string strName, int intAge)
{
Name=Console.ReadLine();
Age=Console.ReadLine();
//Console.WriteLine(Name,Age);
改为Console.WriteLine(Name+" "+ Age.ToString());}static void Main()
{
Employee emp=new Employee();
emp.Information("李白",800);emp.Information();
Console.WriteLine();
}
}
System.Console.Read();
class Employee
{string Name;
string Age;
public void Information()
{Console.WriteLine("李克勤");}
public void Information2(/*string strName, int intAge*/)
{
Console.WriteLine("please type new employee's name :");
this.Name=Console.ReadLine();
Console.WriteLine("please type new employee's age:");
this.Age=Console.ReadLine();
Console.WriteLine("the new employee's name:{0}:",this.Name);
Console.WriteLine("the new employee's arg:{0}:",this.Age);}
原程序升级1.0
class Employee
{string Name;
string Age;
public void Information()
{Console.WriteLine("李克勤");}
public void Information2(/*string strName, int intAge*/)
{
Console.WriteLine("please type new employee's name :");
this.Name=Console.ReadLine();
Console.WriteLine("please type new employee's age:");
this.Age=Console.ReadLine();
Console.WriteLine("the new employee's name:{0}:",this.Name);
Console.WriteLine("the new employee's arg:{0}:",this.Age);}static void Main(/*string[] args*/)
{
Employee emp=new Employee();
emp.Information2(/*"李白",800*/);emp.Information();
}
}
应该是这个,谢谢你的学习素材
{
Name=Console.ReadLine();
Age=Console.ReadLine();
Console.WriteLine(Name,Age);
}
应该是这个函数错误,因为此函数的两个参数在函数中你根本没有用过,而你用了类中的两个相关的属性,因此在后面的emp.Information("李白",800)中“李白”和“800”就无法显示了,而你在实例类也也没有对类的两个属性进行初始化,所以当然为空了。
此函数应改为:
public void Information(string strName, int intAge)
{
strName=Console.ReadLine();
strAge=Console.ReadLine();
Console.WriteLine(Name,Age);
}
{
strName=Console.ReadLine();
strAge=Console.ReadLine();
Console.WriteLine(atrName,strAge);
}