C
C#14mo ago
trench

❔ started coding today and i cannot get past this brick wall any help?

15 Replies
Jimmacle
Jimmacle14mo ago
what kind of data is your IsValidDate method expecting?
trench
trench14mo ago
its supposed to output a true/false
Jimmacle
Jimmacle14mo ago
right, but what data do you have to put in to get that out? what type is the argument of the method?
trench
trench14mo ago
do you mean the data thats put in by the user?
Jimmacle
Jimmacle14mo ago
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)?
trench
trench14mo ago
ooo im not exactly sure but i guess its because im trying to pass the DateTime data and thats whats causing the error?
Jimmacle
Jimmacle14mo ago
correct
trench
trench14mo ago
oh my god that actually solved the problem
Keswiik
Keswiik14mo ago
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.
trench
trench14mo ago
thank you heartowo
Jimmacle
Jimmacle14mo ago
yeah, i ignored the part where checking if a DateTime is a date is irrelevant for the sake of helping him understand the error LUL want to use your method with the string returned by Console.ReadLine before trying to convert it to a DateTime
Keswiik
Keswiik14mo ago
Figured I'd point it out since he'd likely be back once it blows up, lol.
trench
trench14mo ago
this feels like learning math in a different language
Jimmacle
Jimmacle14mo ago
also, FWIW you should avoid using conversions in the Convert class and use the Parse method on your data type instead for example
- Convert.ToDateTime(Console.ReadLine());
+ DateTime.Parse(Console.ReadLine());
- Convert.ToDateTime(Console.ReadLine());
+ DateTime.Parse(Console.ReadLine());
Accord
Accord14mo ago
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.