Consider this class:
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;
}
}
}
I then create a new object like this:
Item item1 = new Item("Item1", "Description...");
Now the problem, I cannot access properties of the object with the getter method, i.e. this doesn't work:
Console.WriteLine(item1.Name);
Console.WriteLine(item1.Description);
Console.ReadLine();
By "doesn't work" I mean when I click on "Start debugging", the console window appears but nothing is there, it's blank. However, this works fine:
Console.WriteLine(item1); // ToString()
Console.ReadLine();
What am I doing wrong?
Richard