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. Array of objects

Array of objects

Scheduled Pinned Locked Moved C#
helpquestiondata-structures
4 Posts 2 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.
  • E Offline
    E Offline
    eric_tran
    wrote on last edited by
    #1

    Good day everyone, I have a problem that I really need someone help. I have an array of objects that is filled from the content of a text file. One line in ther text file contains name,address and employeeID. The problem is that I can not compare the employeeID in the object with a given employeeID. How can I get the value of employeeID out of the the array of objects? Please help.Thanks much in advance Employee[] employeeList = new Employee[100]; employeeList = new Employee[100]; EmpFileReader empfile = new EmpFileReader(); employeeList = empfile.readFile(); //getEmployeeID returns ID if(employeeList[i].getEmployeeID()== employeeID ) System.out.println(employeeList[i]);

    eric

    M 1 Reply Last reply
    0
    • E eric_tran

      Good day everyone, I have a problem that I really need someone help. I have an array of objects that is filled from the content of a text file. One line in ther text file contains name,address and employeeID. The problem is that I can not compare the employeeID in the object with a given employeeID. How can I get the value of employeeID out of the the array of objects? Please help.Thanks much in advance Employee[] employeeList = new Employee[100]; employeeList = new Employee[100]; EmpFileReader empfile = new EmpFileReader(); employeeList = empfile.readFile(); //getEmployeeID returns ID if(employeeList[i].getEmployeeID()== employeeID ) System.out.println(employeeList[i]);

      eric

      M Offline
      M Offline
      Michael Sync
      wrote on last edited by
      #2

      First thing you need to do is that you have to ensure whether readFile() method can parse the value from text file to the employee object. Once you are sure about readFile(), you can just loop through the array and compare the ID..

      eric_tran wrote:

      Employee[] employeeList = new Employee[100]; employeeList = new Employee[100];

      No need to instantiate the array twice. btw.

      Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

      E 1 Reply Last reply
      0
      • M Michael Sync

        First thing you need to do is that you have to ensure whether readFile() method can parse the value from text file to the employee object. Once you are sure about readFile(), you can just loop through the array and compare the ID..

        eric_tran wrote:

        Employee[] employeeList = new Employee[100]; employeeList = new Employee[100];

        No need to instantiate the array twice. btw.

        Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

        E Offline
        E Offline
        eric_tran
        wrote on last edited by
        #3

        Hi Michael, I'm sure that the array of object has all data pulled from the text file. I can get the value of employeeID from the array of object, but when I compare with a given string, then it does not work. for (int i=0; i { if(employeeList[i].getEmployeeID()== "1234" ) System.out.println(employeeList[i]); }

        eric

        modified on Sunday, December 30, 2007 6:25:21 AM

        M 1 Reply Last reply
        0
        • E eric_tran

          Hi Michael, I'm sure that the array of object has all data pulled from the text file. I can get the value of employeeID from the array of object, but when I compare with a given string, then it does not work. for (int i=0; i { if(employeeList[i].getEmployeeID()== "1234" ) System.out.println(employeeList[i]); }

          eric

          modified on Sunday, December 30, 2007 6:25:21 AM

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          Try to write all id of employees array.. see whether you got all employee ids (including the one that you want to search) or not.. For each(Employee emp in Employees){ Console.WriteLine(emp.ID.ToString()); }

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net)

          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