15 Replies
what kind of data is your IsValidDate method expecting?
its supposed to output a true/false
right, but what data do you have to put in to get that out?
what type is the argument of the method?
do you mean the data thats put in by the user?
i mean the data that you are passing into the method when you call it
in
public static bool IsValidDate(string date)
, the string date
is the argument
does that match the data type of the variable you're passing in when you call it like IsValidDate(dateInput)
?ooo im not exactly sure but i guess its because im trying to pass the DateTime data and thats whats causing the error?
correct
oh my god that actually solved the problem
it would be important to note that you are already converting the string you get from the console before you validate your datetime.
So you could throw a format exception which will crash your program.
Here is some relevant documentation: https://learn.microsoft.com/en-us/dotnet/api/system.convert.todatetime?view=net-7.0#system-convert-todatetime(system-string)
Convert.ToDateTime Method (System)
Converts a specified value to a DateTime value.
thank you
yeah, i ignored the part where checking if a DateTime is a date is irrelevant for the sake of helping him understand the error want to use your method with the string returned by Console.ReadLine before trying to convert it to a DateTime
Figured I'd point it out since he'd likely be back once it blows up, lol.
this feels like learning math in a different language
also, FWIW you should avoid using conversions in the
Convert
class and use the Parse
method on your data type instead
for example
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.