Click here to Skip to main content
15,921,250 members
Home / Discussions / C#
   

C#

 
GeneralRe: settings file in relaunching the application Pin
KRISHNARAYALU27-Mar-13 7:39
KRISHNARAYALU27-Mar-13 7:39 
GeneralRe: settings file in relaunching the application Pin
Richard MacCutchan27-Mar-13 7:46
mveRichard MacCutchan27-Mar-13 7:46 
GeneralRe: settings file in relaunching the application Pin
KRISHNARAYALU27-Mar-13 17:05
KRISHNARAYALU27-Mar-13 17:05 
GeneralRe: settings file in relaunching the application Pin
Richard MacCutchan27-Mar-13 23:58
mveRichard MacCutchan27-Mar-13 23:58 
QuestionC# Convertion Pin
Midnight Ahri26-Mar-13 17:20
Midnight Ahri26-Mar-13 17:20 
AnswerRe: C# Convertion PinPopular
parths26-Mar-13 21:08
parths26-Mar-13 21:08 
GeneralRe: C# Convertion Pin
OriginalGriff26-Mar-13 21:21
mveOriginalGriff26-Mar-13 21:21 
GeneralRe: C# Convertion Pin
parths26-Mar-13 21:28
parths26-Mar-13 21:28 
GeneralRe: C# Convertion Pin
OriginalGriff26-Mar-13 21:34
mveOriginalGriff26-Mar-13 21:34 
GeneralRe: C# Convertion Pin
parths26-Mar-13 21:45
parths26-Mar-13 21:45 
AnswerRe: C# Convertion Pin
Midnight Ahri26-Mar-13 22:08
Midnight Ahri26-Mar-13 22:08 
GeneralRe: C# Convertion Pin
harold aptroot27-Mar-13 0:28
harold aptroot27-Mar-13 0:28 
AnswerRe: C# Convertion Pin
OriginalGriff26-Mar-13 21:33
mveOriginalGriff26-Mar-13 21:33 
GeneralRe: C# Convertion Pin
Richard MacCutchan26-Mar-13 22:54
mveRichard MacCutchan26-Mar-13 22:54 
GeneralRe: C# Convertion Pin
OriginalGriff26-Mar-13 22:57
mveOriginalGriff26-Mar-13 22:57 
GeneralRe: C# Convertion Pin
Keith Barrow26-Mar-13 23:51
professionalKeith Barrow26-Mar-13 23:51 
AnswerRe: C# Convertion Pin
V.26-Mar-13 22:29
professionalV.26-Mar-13 22:29 
just to complete the information.

casting is often used in boxing/unboxing objects and is often an expensive operation.
I didn't test, but I think that

C#
txtValue == (string)a;


is a heavier operation than

C#
txtValue = a.ToString();


with the additional problem that you get an exception if it cannot be cast. try/catch is also heavier then if/else. (so if(a != null) { txtValue = a.ToString() } is better than using try/catch. (this is what I call defensive programming)

If you write your own class and override the ToString method, you can do some fancy stuff. eg. if you do NOT override, ToString will probably return something like "thenamespace.theclassname". If you do override it you can make a representation of your class like eg a JSON object or an XML string (or whatever format takes your fancy) with all property values in there. (serializing objects)

C#
txtValue = Convert.ToString(a);


will convert the object to string, but in a safer way. In fact I rarely use the casting (option 1), only if I need to cast from a boxed object. I only use option 2 when I want to do fancy stuff with my class (because of the null reference exception problem.) I use option 3 in most normal cases.

hope this helps.

QuestionLinq To SQL Left Join Pin
Kevin Marois26-Mar-13 17:01
professionalKevin Marois26-Mar-13 17:01 
AnswerRe: Linq To SQL Left Join Pin
Simon_Whale26-Mar-13 23:19
Simon_Whale26-Mar-13 23:19 
Questionserialization / type cast differs between service and console execution Pin
JudyL_MD26-Mar-13 14:20
JudyL_MD26-Mar-13 14:20 
GeneralRe: serialization / type cast differs between service and console execution Pin
JudyL_MD26-Mar-13 14:22
JudyL_MD26-Mar-13 14:22 
AnswerRe: serialization / type cast differs between service and console execution Pin
Dave Kreskowiak26-Mar-13 14:39
mveDave Kreskowiak26-Mar-13 14:39 
QuestionRe: serialization / type cast differs between service and console execution Pin
JudyL_MD26-Mar-13 15:13
JudyL_MD26-Mar-13 15:13 
AnswerRe: serialization / type cast differs between service and console execution Pin
Mycroft Holmes26-Mar-13 15:34
professionalMycroft Holmes26-Mar-13 15:34 
GeneralRe: serialization / type cast differs between service and console execution Pin
JudyL_MD26-Mar-13 16:21
JudyL_MD26-Mar-13 16:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.