Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Editing values in List?

Editing values in List?

Scheduled Pinned Locked Moved C#
helpquestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 10441939
    wrote on last edited by
    #1

    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.

    L P M B E 5 Replies Last reply
    0
    • M Member 10441939

      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.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Member 10441939

        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.

        P Offline
        P Offline
        pradeep surya
        wrote on last edited by
        #3

        Just Add some items to the list TracksOniTunes. Then u can edit the inner values.

        1 Reply Last reply
        0
        • M Member 10441939

          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.

          M Offline
          M Offline
          Member 10441939
          wrote on last edited by
          #4

          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));
          }

          L 1 Reply Last reply
          0
          • M Member 10441939

            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.

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • M Member 10441939

              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));
              }

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • M Member 10441939

                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.

                E Offline
                E Offline
                Emre Ataseven
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups