Click here to Skip to main content
15,886,199 members
Home / Discussions / C#
   

C#

 
QuestionC# Search Button Pin
MikeK322-Nov-12 10:57
MikeK322-Nov-12 10:57 
AnswerRe: C# Search Button Pin
fjdiewornncalwe2-Nov-12 11:19
professionalfjdiewornncalwe2-Nov-12 11:19 
GeneralRe: C# Search Button Pin
MikeK322-Nov-12 11:23
MikeK322-Nov-12 11:23 
GeneralRe: C# Search Button Pin
fjdiewornncalwe2-Nov-12 11:26
professionalfjdiewornncalwe2-Nov-12 11:26 
GeneralRe: C# Search Button Pin
MikeK322-Nov-12 11:51
MikeK322-Nov-12 11:51 
GeneralRe: C# Search Button Pin
fjdiewornncalwe2-Nov-12 11:53
professionalfjdiewornncalwe2-Nov-12 11:53 
Questioncase insensitive string comparison - relative speed Pin
Blake Miller2-Nov-12 9:31
Blake Miller2-Nov-12 9:31 
AnswerRe: case insensitive string comparison - relative speed Pin
Eddy Vluggen2-Nov-12 9:43
professionalEddy Vluggen2-Nov-12 9:43 
Blake Miller wrote:
Under what conditions might the relative speed vary?
  • strings are reference-types, and atomic in memory
  • Converting them both before the comparison is slower than comparing them directly (there can be only one!)
  • Microsoft "advises" to use uppercase constants. Has something to do with efficiency in comparing.
  • Does it matter?

The last point is the most important one; readability is important, as it influences maintainability. If you're doing a lot of string-operations, consider a RegEx for the job.

-edit;
Many string operations, most important the Compare and Equals methods, now provide an overload that accepts a StringComparision enumeration value as a parameter.

When you specify either StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, the string comparison will be non-linguistic. That is, the features that are specific to the natural language are ignored when making comparison decisions. This means the decisions are based on simple byte comparisons and ignore casing or equivalence tables that are parameterized by culture. As a result, by explicitly setting the parameter to either the StringComparison.Ordinal or StringComparison.OrdinalIgnoreCase, your code often gains speed, increases correctness, and becomes more reliable.

It's one of FxCops' warnings[^] Smile | :)
Bastard Programmer from Hell Suspicious | :suss:
if you can't read my code, try converting it here[^]


modified 2-Nov-12 16:25pm.

GeneralRe: case insensitive string comparison - relative speed Pin
Blake Miller2-Nov-12 10:26
Blake Miller2-Nov-12 10:26 
GeneralRe: case insensitive string comparison - relative speed Pin
Eddy Vluggen2-Nov-12 10:29
professionalEddy Vluggen2-Nov-12 10:29 
GeneralRe: case insensitive string comparison - relative speed Pin
SledgeHammer012-Nov-12 11:20
SledgeHammer012-Nov-12 11:20 
AnswerRe: case insensitive string comparison - relative speed Pin
Richard Deeming2-Nov-12 9:47
mveRichard Deeming2-Nov-12 9:47 
GeneralRe: case insensitive string comparison - relative speed Pin
Blake Miller2-Nov-12 10:28
Blake Miller2-Nov-12 10:28 
AnswerRe: case insensitive string comparison - relative speed Pin
Clifford Nelson2-Nov-12 10:18
Clifford Nelson2-Nov-12 10:18 
GeneralRe: case insensitive string comparison - relative speed Pin
Blake Miller2-Nov-12 10:28
Blake Miller2-Nov-12 10:28 
AnswerRe: case insensitive string comparison - relative speed Pin
jschell2-Nov-12 12:46
jschell2-Nov-12 12:46 
QuestionSpell checker in code Pin
PozzaVecia2-Nov-12 9:11
PozzaVecia2-Nov-12 9:11 
AnswerRe: Spell checker in code Pin
Eddy Vluggen2-Nov-12 9:38
professionalEddy Vluggen2-Nov-12 9:38 
GeneralRe: Spell checker in code Pin
PozzaVecia2-Nov-12 9:44
PozzaVecia2-Nov-12 9:44 
GeneralRe: Spell checker in code Pin
Eddy Vluggen2-Nov-12 10:11
professionalEddy Vluggen2-Nov-12 10:11 
GeneralRe: Spell checker in code Pin
PozzaVecia2-Nov-12 11:22
PozzaVecia2-Nov-12 11:22 
AnswerRe: Spell checker in code Pin
Eddy Vluggen2-Nov-12 11:31
professionalEddy Vluggen2-Nov-12 11:31 
AnswerRe: Spell checker in code Pin
Clifford Nelson2-Nov-12 10:26
Clifford Nelson2-Nov-12 10:26 
GeneralRe: Spell checker in code Pin
PozzaVecia2-Nov-12 11:22
PozzaVecia2-Nov-12 11:22 
QuestionSource file with repetitive data Pin
C-P-User-32-Nov-12 6:02
C-P-User-32-Nov-12 6:02 

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.