Win Surprise Gifts!!!
Top 5 Contributors of the Month
Post New Question
Subscribe to Interview Questions
Posted By :
Syed Shakeer Hussain
Posted Date :
November 24, 2009
You can also find related Interview Question to
What is the difference between convert.to.string and .to.string() method?
Convert function handles nulls while i.string() does not it will throw a null reference exception error.
How do I convert a numeric type to a string?
Call Sytem.Object.ToString(). For example, if the variable count is an integer, write the following:
string text = count.ToString();
The second method will get executed and the first method will not be referred.
What is Difference Between ToString() vs Convert.ToString() vs (string) cast
There is a simple but important difference between these three.
ToString() raise exception when the object is null
So in the case of object.ToString(), if object is null, it raise NullReferenceException.
Convert.ToString() return string.Empty in case of null object
(string) cast assign the object in case of null
So in case of
MyObject o = (string)NullObject;
But when you use o to access any property, it will raise NullReferenceException.
Eg: ClientScript.RegisterStartupScript(GetType(), "key", "script");
What is the difference between Convert.toString and .toString()
Just to give an understanding of what the above question means see the below code :-
int val = 0;
We can convert the integer "val" using "val.ToString()" or "Convert.ToString" so what's the difference.
The basic difference between them is "Convert" function handles NULLS while "val.ToString()"
It will throw a NULL reference exception error. So as good coding practice using "Convert" is always safe.
What is the difference between Convert.ToString() and .ToString() method.
Have a look at the following program and its output
static void Main(string args)
String UserName = null ;
//Below statement WILL THROW an exception as .ToString() does not handles null values
String strUserId = UserName.ToString();
catch (NullReferenceException ex)
//Below statement WILL NOT THROW an exception as convert.tostring handles implicitly
String strUserId = Convert.ToString(UserName);
catch (NullReferenceException ex)
Below is the output of the console application
Error:Object reference not set to an instance of an object.
Press any key to continue . . .
What is the method to convert one type to another using Lambda expressions?
Which Build-in Function Use to Convert Lowercase Into Uppercase in VBScript
How To Convert String to Integer in vb script or Numberformat.
Normally We Can Convert String To Integer using some Built-in Function.
Use Build in function Length
like String.length. it will return int.
What is Method overloading?
Method overloading occurs when a class contains two methods with the same name, but different signatures.
What is Method Overriding? How to override a function in C#?
Use the override modifier to modify a method, a property, an indexer, or an event. An override method provides a new implementation of a member inherited from a base class. The method overridden by an override declaration is known as the overridden base method. The overridden base method must have the same signature as the override method.
You cannot override a non-virtual or static method. The overridden base method must be virtual, abstract, or override.
Can we call a base class method without creating instance?
Its possible If its a static method.
Its possible by inheriting from that class also.
Its possible from derived classes using base keyword.
Quick Links For Interview Questions Categories:
Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.
So, Start looking our
section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.
Hall of Fame
Terms of Service
Tell A Friend