In this program ToString() method is function as casting, because it is converting one data type to other. I wish to know whether my understanding is correct.
using System;
class Program
{
static void Main()
{
int a = 4000;
string a1 = a.ToString();
Console.WriteLine(a1);
Console.ReadKey();
}
}
Loading
Jignesh TrivediPosted Sep 24, 2013, 1:14 AM
Yes your understanding is correct....
agree with vulpes use Convert.Tostring method instead of ToString method because it able to handle null value....
Posted Sep 23, 2013, 1:24 PM
VulpesPosted Sep 23, 2013, 10:38 AM
Off the top of my head, this includes:
// conversion of basic numeric types
double d = 2.0;
int i = (int)d;
// unboxing value types
object o = 3;
int i = (int)o;
// recovering a derived class reference from a parent class variable
Derived d = new Derived();
Parent p = d
Derived d2 = (Derived)p;
// or if 'p' might be null, you can avoid an exception with:
Derived d3 = p as Derived;
Posted Sep 23, 2013, 10:21 AM
VulpesPosted Sep 23, 2013, 10:03 AM