0

Trying to build a Windows 8 App using C# and XAML.

I've created a class:

class Tile
{
    public Tile(int ID, string Name, double Frequency, double Divider, int Value, int Turns, int StartLevel)
    {
        this.ID = ID;
        this.Name = Name;
        this.Frequency = Frequency;
        this.Divider = Divider;
        this.Value = Value;
        this.Turns = Turns;
        this.StartLevel = StartLevel;
    }

    private int ID { get; set; }
    private string Name { get; set; }
    private double Frequency { get; set; }
    private double Divider { get; set; }
    private int Value { get; set; }
    private int Turns { get; set; }
    private int StartLevel { get; set; }
}

I've added objects to a list:

List<Tile> tList = new List<Tile>();

tList.Add(new Tile(0, "Example1", 0.08, 1.00, 0, 7, 1));
tList.Add(new Tile(1, "Example2", 0.21, 1.25, 0, 0, 1));

When using standard C#, I'm able to access the properties of an object like such:

foreach (Tile t in tList)
{
    int test = t.ID;
}

The Problem: In my foreach statement above, when I type "t." all that comes up in this list of available elements is:

Equals GetHashCode GetType ToString

I Expect: The following elements to appear:

ID Name Frequency Divider Value Turns StartLevel

What am I missing here?


Since you pass form variable to the block passed to form_for method, you should substitute f with form.

4

1 に答える 1

4

Tile クラスのプロパティはプライベートに設定されています。クラス外からプロパティにアクセスできるようにするには、プロパティを public として宣言する必要があります。

public class Tile
{
    public int ID { get; set; }
    public string Name { get; set; }
    public double Frequency { get; set; }
    public double Divider { get; set; }
    public int Value { get; set; }
    public int Turns { get; set; }
    public int StartLevel { get; set; }
}

同じコンストラクターを保持できますが、プロパティを追加/減算すると、維持するのが面倒になります。Tile オブジェクトのリストをインスタンス化する別の方法は次のとおりです。

List<Tile> tList = new List<Tile>
{
    new Tile
    {
       ID = 0,
       Name = "Example1"
    }
};

...設定する必要がある数のパブリック プロパティに対して。

于 2013-06-15T21:31:30.570 に答える