In C#, you can use the DateTime.Parse or DateTime.TryParse method to convert a string to a DateTime object.
Here's an example:
we use the DateTime.TryParse method to convert the string "2022-03-05" to a DateTime object. If the conversion is successful, we print the date and time using the ToString method. If the conversion fails, we print an error message.
Note that you can also use DateTime.Parse method instead of DateTime.TryParse, but it will throw an exception if the conversion fails.