C# automatically converts smaller types to larger compatible types:
int num = 42;
double result = num; // implicitly equal to 42.0, but will print 42
Console.WriteLine(result);Use parentheses to cast when there may be a loss of data:
Use the Convert class to safely convert between types:
Use int.Parse() or double.Parse() to convert from strings:
Use TryParse() to avoid crashes on bad input:
Not all types can be cast. For example, casting a string directly to int without parsing will throw an exception.
What does this print?
A. 10B. 10.0C. ErrorAsk the AI if you need help understanding or want to dive deeper in any topic