考虑这个类:C#控制台问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Game.Items
{
class Item
{
private string name;
public string Name
{
get { return this.name; }
}
private string description;
public string Description
{
get { return this.description; }
}
public Item(string name, string description)
{
this.name = name;
this.description = description;
}
public override string ToString()
{
return this.name;
}
}
}
我然后创建一个新的对象是这样的:
Item item1 = new Item("Item1", "Description...");
现在的问题,我不能与getter方法,即访问该对象的属性这是行不通的:
Console.WriteLine(item1.Name);
Console.WriteLine(item1.Description);
Console.ReadLine();
“不工作”我的意思是当我点击“开始调试”,控制台窗口出现,但没有g在那里,它是空白的。但是,这工作正常:
Console.WriteLine(item1); // ToString()
Console.ReadLine();
我做错了什么?
理查德
如果你还没有,请尝试安装ReSharper的的30天免费试用 - 它会检测并提供解决众多之类的命名空间的问题,保护问题和诸如此类的东西......以及建议良好的命名习惯 - 良好的学习材料。 – 2009-04-25 13:14:20
当你说“这不起作用”时,你究竟是什么意思?编译器错误?运行时错误?不正确的结果?崩溃? – 2009-04-25 13:15:14
换行符是打印还是什么都没有? “Console.ReadLine”怎么样?它工作吗? – 2009-04-25 13:44:37