Editing values in List?
-
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
-
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
Simple. In the line:
List<Track> TracksOniTunes = new List<Track>();
You are creating a brand new empty List. So when you get to
foreach (Track item in TracksOniTunes)
there is nothing in your list. You have to put something in your list before you can change its properties.
-
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
Just Add some items to the list TracksOniTunes. Then u can edit the inner values.
-
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
Sorry, here is the line that add a Track to the list
for (int countForTrack = countTracks; countForTrack > 0; countForTrack--)
{
currentTrack = tracks[countTracks] as IITFileOrCDTrack;
countTracks--;
TracksOniTunes.Add(new Track(currentTrack.Name, currentTrack.Artist, currentTrack.Album, currentTrack.SampleRate, currentTrack.BitRate));
} -
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
Member 10441939 wrote:
My Problem is that i can't editing some items?
I can not access the objects.What specific error message do you get, and where in the code does the error occur ? I note in your second reply you do not use the for-loop index count variable to access the current Track, but instead use and decrement another variable: this is not an error, but, why not use the for-loop index variable ?
“I speak in a poem of the ancient food of heroes: humiliation, unhappiness, discord. Those things are given to us to transform, so that we may make from the miserable circumstances of our lives things that are eternal, or aspire to be so.” Jorge Luis Borges
-
Sorry, here is the line that add a Track to the list
for (int countForTrack = countTracks; countForTrack > 0; countForTrack--)
{
currentTrack = tracks[countTracks] as IITFileOrCDTrack;
countTracks--;
TracksOniTunes.Add(new Track(currentTrack.Name, currentTrack.Artist, currentTrack.Album, currentTrack.SampleRate, currentTrack.BitRate));
}Okay... since you say that there are actually items in your List, the problem becomes more clear. In your foreach you need to say
item.SampleRate = 0;
But to get to the variables, you either need to make your class level variables public or create public properties for your class exposing those variables to outside that class.
-
Hy @ everyone, i have a Little Problem:
class Track
{
string Name;
string Artist;
string Album;
int SampleRate;
int BitRate;public Track(string name, string artist, string album, int sampleRate, int bitRate) { Name = name; Artist = artist; Album = album; SampleRate = sampleRate; BitRate = bitRate; }
}
Now i want to editing some values foreach Track:
List TracksOniTunes = new List();
foreach (Track item in TracksOniTunes)
{
// SampleRate = 0}
Later, i have a Switch and I need depending on different values to compare from the List
switch (criteria)
{
case "":
break;
case "Qualität":
break;
case "Album":
break;
case "Compilation":
break;
}My Problem is that i can't editing some items? I can not access the objects. Is there an easy way? Thanks for help.
Change your fields to auto-properties like that;
public string Name { get; set; }
public string Artist{ get; set; }
public string Album { get; set; }Tim Toady Bicarbonate