1

I want to have a class where I can set and get for each note. So I parse an XML file and with each <note> attribute in the file, I set and get the Note class. This was an alternative method to the Dictionary<int,string> that I had last time.

So why did I change it? Because for the double notes, (when the times were the same), the int within the dictionary would be a duplicate key and throw an error. So now, I've made a list with my Note class.

Here's the note class:

class Note
{
    public enum Notes
    {
        A, S, D, J, K, L,
    };

    public Notes CurrentNote { get; set; }

    public string Time { get; set; }

    public Note(Notes Note, string Time) {
        this.CurrentNote = Note;
        this.Time = Time;
    }
}

And then in my NoteManager.cs, I'll add to the list and set the values through that. But I'm not totally sure if this will work? I've never worked with getting and setting of classes. I tried adding the Notes to the list, but the way that I get the values doesn't seem to work. It gives a weird output.

System.Linq.Enumberable+D_3a`1[Hit_Machine.Managers.Note]

Here's the NoteManager.cs Class:

class NoteManager : Game1
{
    public static List<Note> Notes = new List<Note>();

    public static void addNotes() {
        Notes.Add(new Note(Note.Notes.A, "22.22"));
        Notes.Add(new Note(Note.Notes.A, "33.33"));
        Notes.Add(new Note(Note.Notes.A, "55.55"));
    }

    public static void getNotes(Game1 Parent)
    {
        Game1.myGameText = Notes.Take(5).ToString();
    }
}

So what actually would be the proper way of using this method?

gunr2171
  • 10,315
  • 25
  • 52
  • 75
Jarrod
  • 312
  • 1
  • 3
  • 13
  • I'm guessing that the way that I'm using is wrong, and for each note that I set, it's just redefining the class, it's not actually saving that? – Jarrod Dec 20 '13 at 18:55
  • What text do you expect to appear? You basically create an enumerator that yields five elements of the `Notes` list. That's what the `ToString()` method returns ("I can enumerate some `Notes`"). – Nico Schertler Dec 20 '13 at 19:05
  • Yeah, sorry, after some further research, I found that the method I was using was right. All I had to do was simply Notes[1].CurrentNote.ToString() simply returned what I needed. Thankyou for your interest :) – Jarrod Dec 20 '13 at 19:08
  • Use a collection type that allows duplicates. http://stackoverflow.com/questions/146204/duplicate-keys-in-net-dictionaries – user3123818 Dec 20 '13 at 19:13

0 Answers0