I've been working on an app to manage my iTunes collection, and have run into a bit of a snag. I've created two classes: Column – Describes a column of information in the iTunes database Track – Contains an array of Columns When I instantiate a new Track object and attempt to build the array of Columns, each "new Column" statement overwrites the value of the previous array element. I'm sure I'm missing something obvious – any ideas?
// this statement... Track t = new Track(); // produces this output: // array element 0 = Name // array element 0 = Artist // array element 1 = Artist // Begin Column class using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestBed { public class Column { private static string _name; private static string _datatype = "string"; private static Int16 _length = 0; public string Name { get { return _name; } set { _name = value; } } public string DataType { get { return _datatype; } set { _datatype = value; } } public Int16 Length { get { return _length; } set { _length = value; } } public Column(string name, string datatype, Int16 length) { _name = name; _datatype = datatype; if (datatype == "string" && length > 0) {_length = length; } else {_length = 0;} } } } // Begin Track class using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace TestBed { public class Track { private static Column[] _trackcolumns = new Column[2]; public static Column[] TrackColumns { get {return _trackcolumns;} set { _trackcolumns = value; } } public Track() { _trackcolumns[0] = new Column("Name", "string", 30); Console.WriteLine("array element 0 = {0}",_trackcolumns[0].Name); _trackcolumns[1] = new Column("Artist", "string", 30); Console.WriteLine("array element 0 = {0}", _trackcolumns[0].Name); Console.WriteLine("array element 1 = {0}", _trackcolumns[1].Name); } }
static
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)