Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# How can I center the PictureBox to the Parent from code? ( Windows Forms ) Pin
Karl Henrry11-Jan-18 14:12
Karl Henrry11-Jan-18 14:12 
QuestionBest Temporary storage for DataGrid in C# Pin
Member 1359640810-Jan-18 13:17
Member 1359640810-Jan-18 13:17 
AnswerRe: Best Temporary storage for DataGrid in C# Pin
OriginalGriff10-Jan-18 19:51
mveOriginalGriff10-Jan-18 19:51 
AnswerRe: Best Temporary storage for DataGrid in C# Pin
Eddy Vluggen11-Jan-18 1:03
professionalEddy Vluggen11-Jan-18 1:03 
Questionc# Introduction Pin
ormonds10-Jan-18 10:39
ormonds10-Jan-18 10:39 
AnswerRe: c# Introduction Pin
OriginalGriff10-Jan-18 19:49
mveOriginalGriff10-Jan-18 19:49 
GeneralRe: c# Introduction Pin
ormonds10-Jan-18 23:14
ormonds10-Jan-18 23:14 
GeneralRe: c# Introduction Pin
OriginalGriff10-Jan-18 23:25
mveOriginalGriff10-Jan-18 23:25 
AnswerRe: c# Introduction Pin
Richard MacCutchan10-Jan-18 22:28
mveRichard MacCutchan10-Jan-18 22:28 
GeneralRe: c# Introduction Pin
ormonds10-Jan-18 23:14
ormonds10-Jan-18 23:14 
QuestionHow to compare string data by value and by reference Pin
Mou_kol8-Jan-18 20:59
Mou_kol8-Jan-18 20:59 
AnswerRe: How to compare string data by value and by reference Pin
OriginalGriff8-Jan-18 21:24
mveOriginalGriff8-Jan-18 21:24 
AnswerRe: How to compare string data by value and by reference Pin
Bernhard Hiller9-Jan-18 21:41
Bernhard Hiller9-Jan-18 21:41 
GeneralRe: How to compare string data by value and by reference Pin
OriginalGriff10-Jan-18 0:38
mveOriginalGriff10-Jan-18 0:38 
GeneralRe: How to compare string data by value and by reference Pin
Mou_kol10-Jan-18 21:18
Mou_kol10-Jan-18 21:18 
GeneralRe: How to compare string data by value and by reference Pin
OriginalGriff10-Jan-18 22:02
mveOriginalGriff10-Jan-18 22:02 
GeneralRe: How to compare string data by value and by reference Pin
Mou_kol11-Jan-18 3:42
Mou_kol11-Jan-18 3:42 
GeneralRe: How to compare string data by value and by reference Pin
Richard Deeming11-Jan-18 4:05
mveRichard Deeming11-Jan-18 4:05 
GeneralRe: How to compare string data by value and by reference Pin
Mou_kol15-Jan-18 22:00
Mou_kol15-Jan-18 22:00 
GeneralRe: How to compare string data by value and by reference Pin
Richard Deeming16-Jan-18 1:21
mveRichard Deeming16-Jan-18 1:21 
GeneralRe: How to compare string data by value and by reference Pin
Mou_kol16-Jan-18 1:44
Mou_kol16-Jan-18 1:44 
GeneralRe: How to compare string data by value and by reference Pin
OriginalGriff11-Jan-18 4:19
mveOriginalGriff11-Jan-18 4:19 
For a string, a == b is always a value comparison, but ... it starts with a reference comparison!

1) operator == calls string.Equals.
2) The first thing that Equals does is this:
if ((Object)a==(Object)b) return true;

Which is a reference comparison, as you'd expect. A good percentage of the time, this will make the process faster.
3) It then checks for null in either side, and returns false if either is null.
4) It then compares the lengths - any difference is a return false.
5) It then calls another method which repeats those two tests (if it's the debug build) and throws an exception via Contract.Requires
6) It then uses unsafe code with pointers to do a value comparison (but quickly, using 12 bytes at a time for AMD processors, and 10 for Intel - don't ask)

So technically, "a == b" is a value comparison, but it has a few additional tests to speed things up, including a reference comparison.

But you really aren't supposed to know that, the traditional answer is "value comparison for strings". It may be that they wanted you to expand on "value type" and maybe explain why it's not a reference comparison?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

GeneralRe: How to compare string data by value and by reference Pin
Mycroft Holmes11-Jan-18 10:32
professionalMycroft Holmes11-Jan-18 10:32 
GeneralRe: How to compare string data by value and by reference Pin
OriginalGriff11-Jan-18 11:19
mveOriginalGriff11-Jan-18 11:19 
QuestionC# Windows Form Application with 86x unmanaged dll Pin
Zeyad Jalil8-Jan-18 20:33
professionalZeyad Jalil8-Jan-18 20:33 

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.