Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi
I have an application where a user input dates and the output should be the dates of the month that the user didnt input if in august 2012 you putted in 1/08/2012,2/08/2012,3/08/2012 so the output should be those august dates were not entered excluding weekends
I writing a console application which is
C#
// create a writer and open the file
TextWriter tw = new StreamWriter("date.txt");

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();
Posted
Updated 17-Aug-12 4:31am
v2
Comments
fjdiewornncalwe 17-Aug-12 10:33am    
It looks to me like you want us to do your homework for you. It doesn't work that way here. What will you learn by not going through the pains of lectures and course notes.
[no name] 17-Aug-12 10:37am    
In additon, you did not bother asking any kind of a question.
kolisa 17-Aug-12 10:37am    
ok
kolisa 17-Aug-12 10:38am    
feeling so small thanks guys
[no name] 17-Aug-12 10:45am    
kolisa.. where are you stuck ?

I'll try to give you some hints on how you could attempt to solve this.


  1. Create a class called DateCheck with two properties DateTime Date and bool IsPresent
  2. Create a dictionary Dictionary<datetime,> and running throug the days of one month fill the dictionary where the key is the current date in the loop and the value is an instance of DateCheck with Date also set to the current date and IsPresent set to false (that could also be done in the constructor of DateCheck).
  3. Read in the file with the dates in it line by line and:

    1. Parse the date from the line you read from the file (DateTime.TryParse or DateTime.Parse)
    2. Lookup the value in the dictionary that is associated with the date you found in the file
    3. Set IsPresent to true for the value you looked up in the previous step
  4. Iterate over all the values in the dictionary and collect all instances of DateCheck where IsPresent is false.


And you're pretty much done!

Give it a try, you'll work it out all right.

— Manfred
P.S: The filtering of the values from the dictionary could be done by using a LinQ query.
 
Share this answer
 
v3
Comments
Wendelius 17-Aug-12 16:47pm    
Nice :thumbsup:
What you did, is really nothing. You haven't done any of your tasks. What you want to do is to use File.ReadAllLines to get your file as an array of strings. Then DateTime.TryParse to get dates out. Then you need to iterate over all the dates, and store each new month you find in to an array. You can use the Exists method to check if something is in there already, I am not sure .NET has a set class. Finally, you check if each possible date is in the list and emit it if it is not. A list of all the months is the easiest way to do that, iterate over the full list and emit anyting not in the smaller list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900