Case insensitive ‘Contains(string)’

Is there a way to make the following return true? string title = “ASTRINGTOTEST”; title.Contains(“string”); There doesn’t seem to be an overload that allows me to set the case sensitivity. Currently I UPPERCASE them both, but that’s just silly (by which I am referring to the i18n issues that come with up- and down casing). … Read more

How to enumerate an enum

How can you enumerate an enum in C#? E.g. the following code does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { foreach (Suit suit in Suit) { DoSomething(suit); } } And it gives the following compile-time error: ‘Suit’ is a ‘type’ but is used like a ‘variable’ It … Read more

The Definitive C++ Book Guide and List

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. This question attempts to collect the few pearls among the dozens of bad C++ books that are published every year. Unlike many other programming languages, which are often picked up on the … Read more

What is the “–>” operator in C/C++?

After reading Hidden Features and Dark Corners of C++/STL on comp.lang.c++.moderated, I was completely surprised that the following snippet compiled and worked in both Visual Studio 2008 and G++ 4.4. Here’s the code: #include <stdio.h> int main() { int x = 10; while (x –> 0) // x goes to 0 { printf(“%d “, x); … Read more

Why is processing a sorted array faster than processing an unsorted array?

Here is a piece of C++ code that shows some very peculiar behavior. For some strange reason, sorting the data (before the timed region) miraculously makes the loop almost six times faster. #include <algorithm> #include <ctime> #include <iostream> int main() { // Generate data const unsigned arraySize = 32768; int data[arraySize]; for (unsigned c = … Read more