user12170668
user12170668

Reputation:

Accessing the elements of an array

I have a task to create a program to read from a file and check which employees have worked together for longer. I have already created the code to read from a file and store the data in an array. You can check it below:

string path;
do
{
    Console.Write("Please enter the path of the file: ");
    path = Console.ReadLine();

    if (!File.Exists(path))
    {
        Console.WriteLine("The path is not correct.");
    }

} while (!File.Exists(path));

string[] lines = File.ReadAllLines(path);

foreach (string line in lines) //just to check if the program can read from a file
{
    Console.WriteLine(line);
}
Console.WriteLine();



for (int i = 0; i < lines.Length; i++)
{
    string[] values = lines[i].ToString().Split(',');

    foreach (string el in values) //just to check if the value are stored inside the array
    {
        Console.Write(el + " ");
    }
}

Console.ReadLine();

This code gives this result:

Please enter the path of the file: C:\Users\...
143, 12, 2013-11-01, 2014-01-05
145, 10, 2009/01/01, 2011/04/27
140, 10, 2009.03.01, 2011.04.27
111, 10, 2009.03.01, NULL

143  12  2013-11-01  2014-01-05  
145  10  2009/01/01  2011/04/27  
140  10  2009.03.01  2011.04.27  
111  10  2009.03.01  NULL 

(the columns represent: employerID, projectID, DateFrom and DateTo respectively). Now I need to create a code that calculates the time that 2 employees have worked on the same project (using project id and the dates to calculate the period of work together). I need some help to understand how I can do that. Thank you!

Upvotes: 0

Views: 80

Answers (1)

tmaj
tmaj

Reputation: 34947

This could be a good start:

  1. Create a class EmployeeWorkPeriod with the 4 fields
  2. Parse values into data types like int and DateTime (and DateTime?).

Once you have these object you can start writing you program logic.

Upvotes: 1

Related Questions