C
C#2y ago
trench

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

15 Replies
Jimmacle
Jimmacle2y ago
what kind of data is your IsValidDate method expecting?
trench
trenchOP2y ago
its supposed to output a true/false
Jimmacle
Jimmacle2y ago
right, but what data do you have to put in to get that out? what type is the argument of the method?
trench
trenchOP2y ago
do you mean the data thats put in by the user?
Jimmacle
Jimmacle2y 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
trenchOP2y 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
Jimmacle2y ago
correct
trench
trenchOP2y ago
oh my god that actually solved the problem
Keswiik
Keswiik2y 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
trenchOP2y ago
thank you heartowo
Jimmacle
Jimmacle2y 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
Keswiik2y ago
Figured I'd point it out since he'd likely be back once it blows up, lol.
trench
trenchOP2y ago
this feels like learning math in a different language
Jimmacle
Jimmacle2y 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
Accord2y 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.
Want results from more Discord servers?
Add your server