Click here to Skip to main content
14,550,977 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Breaking news: Many members of microsoft upper management fallen into euphoric coma! Pin
Slacker0078-Apr-20 23:38
professionalSlacker0078-Apr-20 23:38 
GeneralRe: Breaking news: Many members of microsoft upper management fallen into euphoric coma! Pin
Sander Rossel9-Apr-20 0:02
professionalSander Rossel9-Apr-20 0:02 
GeneralRe: Breaking news: Many members of microsoft upper management fallen into euphoric coma! Pin
Mark_Wallace9-Apr-20 2:52
MemberMark_Wallace9-Apr-20 2:52 
GeneralRe: Breaking news: Many members of microsoft upper management fallen into euphoric coma! Pin
Johnny J.8-Apr-20 23:05
professionalJohnny J.8-Apr-20 23:05 
GeneralRe: Breaking news: Many members of microsoft upper management fallen into euphoric coma! Pin
Mark_Wallace9-Apr-20 2:55
MemberMark_Wallace9-Apr-20 2:55 
GeneralC# puzzle.... Pin
James Curran8-Apr-20 13:00
MemberJames Curran8-Apr-20 13:00 
GeneralRe: C# puzzle.... Pin
Nish Nishant8-Apr-20 13:30
sitebuilderNish Nishant8-Apr-20 13:30 
GeneralRe: C# puzzle.... Pin
James Curran8-Apr-20 14:02
MemberJames Curran8-Apr-20 14:02 
Hmmmm Very interesting results.

I ran my test using BenchmarkDotNet, with a longer string, with a "~" near the end.

Now, the whole point of this was that I found some code using A, and I figured that B should be faster.

So, I ran the test-- and in mine, B came out way last.

Studying it source code, I found that A just redirects to E, so they were nearly the same.

B, however, uses String's IEnumerable<char> interface to run the Enumerable.Contains<char>() extension method, which is why it was last.

C I tried, mistakenly thinking it would be the same as E. It came out nearly tied with B for last.

D was my overall winner as well.

So, it seems you are experiencing a String.Contains(char) which is specific for strings, which I am not seeing.

I ran the tests on .NET 4.6.1. Are you using .NET Core?
Truth,

James

GeneralRe: C# puzzle.... Pin
Nish Nishant8-Apr-20 14:14
sitebuilderNish Nishant8-Apr-20 14:14 
GeneralRe: C# puzzle.... Pin
Garth J Lancaster8-Apr-20 15:19
professionalGarth J Lancaster8-Apr-20 15:19 
GeneralRe: C# puzzle.... Pin
Nish Nishant9-Apr-20 13:08
sitebuilderNish Nishant9-Apr-20 13:08 
GeneralRe: C# puzzle.... Pin
Nish Nishant8-Apr-20 13:35
sitebuilderNish Nishant8-Apr-20 13:35 
GeneralRe: C# puzzle.... Pin
Mario Vernari8-Apr-20 20:00
MemberMario Vernari8-Apr-20 20:00 
GeneralRe: C# puzzle.... Pin
Nelek8-Apr-20 23:09
protectorNelek8-Apr-20 23:09 
GeneralRe: C# puzzle.... Pin
Jörgen Andersson9-Apr-20 1:24
professionalJörgen Andersson9-Apr-20 1:24 
GeneralRe: C# puzzle.... Pin
Greg Utas8-Apr-20 13:56
professionalGreg Utas8-Apr-20 13:56 
GeneralRe: C# puzzle.... Pin
OriginalGriff8-Apr-20 20:07
mveOriginalGriff8-Apr-20 20:07 
GeneralRe: C# puzzle.... Pin
Greg Utas8-Apr-20 23:11
professionalGreg Utas8-Apr-20 23:11 
GeneralRe: C# puzzle.... Pin
Member 147747708-Apr-20 15:11
MemberMember 147747708-Apr-20 15:11 
GeneralRe: C# puzzle.... Pin
Jörgen Andersson8-Apr-20 20:03
professionalJörgen Andersson8-Apr-20 20:03 
GeneralRe: C# puzzle.... Pin
OriginalGriff8-Apr-20 20:09
mveOriginalGriff8-Apr-20 20:09 
GeneralRe: C# puzzle.... Pin
Nish Nishant9-Apr-20 13:10
sitebuilderNish Nishant9-Apr-20 13:10 
GeneralRe: C# puzzle.... Pin
OriginalGriff8-Apr-20 19:54
mveOriginalGriff8-Apr-20 19:54 
GeneralRe: C# puzzle.... Pin
CPallini8-Apr-20 21:45
mveCPallini8-Apr-20 21:45 
GeneralRe: C# puzzle.... Pin
F-ES Sitecore8-Apr-20 23:52
mveF-ES Sitecore8-Apr-20 23:52 

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.