Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
1.22/5 (2 votes)
See more:
Hi,

How to convert object variable values into string variable values?
Posted
Updated 24-May-20 17:59pm
v3
Comments
Dalek Dave 18-Nov-10 4:26am    
Edited for Grammar.

object myObject = new Object();

string myObjectString = myObject.ToString();
 
Share this answer
 
Comments
fjdiewornncalwe 18-Nov-10 7:22am    
If you are using a class that you have created, you can override the .ToString() method in the source for that class to customize the output.
if object is not null and hold string value
use statement like this-------
VB
Object obj=new Object();
obj="hi";

string str1=Convert.ToString(obj);
string str2=obj.ToString();
string str3= obj as string;
string str4=(string)obj;
 
Share this answer
 
v4
Comments
fjdiewornncalwe 18-Nov-10 7:21am    
If you are using a class that you have created, you can override the .ToString() method in the source for that class to customize the output.
suzeets 18-Jun-11 15:28pm    
Object obj=new Object();
obj="hi";
these are 4 type to convert object to string
string str1=Convert.ToString(obj);
string str2=obj.ToString();
string str3= obj as string;
string str4=(string)obj;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900