I'm using the below code in c sharp. But both the WriteLine statements are giving the same result 25. Then what is the need for converting Tostring in c sharp? Is there any special purpose?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace sample
{
class Program
{
static void Main(string[] args)
{
int value = 25;
Console.WriteLine(value.ToString());
Console.WriteLine(value);
Console.ReadLine();
}
}
}
If I understand your question, the purpose of ToString() is to provide a consistent mechanism to convert objects to strings. In your Console.WriteLine(value); example you are using an Overloaded version of WriteLine that takes an int, but in the general case of using an object the system needs a mechanism of providing a textual representation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With