devxlogo

.NET

The Right Way to Do Insensitive String Comparison

We often do String.ToUpper()?on two strings to compare them. This introduces additional overhead on string allocation. It is better to use OrdinalIgnoreCase?instead, as shown below: bool CompareResult = firstString.Equals(secondString, StringComparison.OrdinalIgnoreCase);

Chaining Null Comparisons with the ?? Operator

Did you know you can chain null comparisons to any level on an object with ?? operator? See below for an example: string inputString;//set some value.var multiEvaluationResult = inputString?? secondaryString

Extending Simple Enum Values to Be Composite

Have you felt a need for enums to have composite values? They can be defined internally within the enum as below: Public enum livingObjects {Humans,Animals,Plants,All = Humans | Animals |

Quickly Test a Block of Code in .NET

Write a test method around the block of code that you want to test as an independent piece. Then, compile the code. Just open the test explorer window and right

Speed Up Entity Framework Queries

Queries like the one below will perform more slowly than they could be run on a varchar column. Explicitly marking them as such will improve the performance of EF queries