❔ What mistake did I make?
attached is my code, but it doesnt generate anything for the objects and has like default values of 0 and the default time for those DateTime objects
25 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
ohh
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
its this first
ahh
ok
yeah i forgot abou thtat
ill fix that, thanks
yeah it works now
@Th'm do you know how to remove the date/time?
i mean
just the time
like i dont want it to include 12:00:00 am
this is something i can search up actually if you dont know
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
@Th'm for some reason i keep getting an erorr of converting from string to system.datetime
when i try to remove the time
@jcotton42 it’s in this thread
But the code I attached originally does not include the fact that I want to convert the date time to just daye
But idk what to include to do that
can you show that bit of code?
and what line is the error on?
also, not sure why you did the properties manually
What framework is this? The verbosity in properties is confusing me 😄
The setters aren't used in your example so the set constraint I think is unnecessary.
For validation of constructor params, you could probably do all that in the constructor. Though, it'll probably get messy, quickly. Not sure what typical convention here is though. For validation, I have a separate method as part of the class to validate its members.
this
keyword used here is unnecessary also and personally I think is ugly 😄Wait so for start date and end date how does it only process date
Not sure the question. I just did 1:1 to your original post
You're just passing the parameters through via constructor. Personally, I'd take this approach instead...
yeah i think the code is fine now like everyhting is wroking from original
and yeah i see that my code isnt the best formatted but because i just started c# i think its fine
its just the fact that when i use the DateTime object it also prints the time
Not saying your code is wrong. It worked. I'm just providing pointers 🙂
and i cant remove that
ah yeah thank yuo
will consider in future
You can use the to string function
yeah but unfortunatley it gives an erorr
ill pull it up rq
its like "cannot convert string to system.datetime"
Console.WriteLine($"End Date: {hurricane.EndDate.ToString("yyyy-MM-dd"}\n")
oh maybe ill try that
This works using string interpolation
If you were doing this outside of string interp, you'd need to use the
.ToString("FORMAT_HERE")
methodgetting a syntax error with this
oh wait
i forgot parenthesis
i think
yep
ok thank you it works!
ill keep the code u provided for reference so i can make my code look neater in futuire
👍
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.