Geeks With Blogs
Abhishek Anand Bits & Bytes about .net technology framework.
Lets start with an Example :int[] listOfNumbers = new int[] { 5, 9, 8, 1, 7, 3, 6, 4, 2, 0 }; int i = 0; var query = from num in listOfNumbers select ++i; // Note, the local variable 'i' is not incremented until each element is evaluated (as a side-effect): foreach (var x in query) { Console.WriteLine("x = {0}, i = {1}", x, i); } Now without deferred ......

Outside of LINQ statements such as .Any(predicate) and .First(predicate) short circuiting execution when a matching element is found, the library does not inherently do any underlying optimizations due to the limits of what is available to it. Since LINQ only works with IEnumerables, the only thing that can be done is to loop through the elements in ......

Cyclomatic Complexity is a widely used software metric that is used to compute the number of decisions being made by a piece of code. In its simplest form, the complexity number is equal to: 1 + {the number of expressions in the method}. Different tools interpret the definition of “expressions” differently, thus the slightly varying metrics based on ......

Here are the steps you need to take to get this feature enabled in your local Visual Studio instance: 1. First select Ctrl+Alt+E, or Debug à Exceptions, to bring up the Exceptions dialog 2. Make sure that all of the check-boxes in the “User-unhandled” column are checked a. Specifically the “Common Language Runtime Exceptions” box must be checked 3. ......

Imagine you are testing a method that returns or processes a Workflow event. Normally, you would generate a fake instance of the class and insert it into the method using Moq. However, creating a fake Workflow event is difficult, as Workflow events do not expose any public constructors. You can generate Workflow events using Microsoft.Activities.UnitTe... ......

You can unit test a class that uses HttpClient by giving that HttpClient a mock HttpMessageHandler. This way, you can capture the request and prevent it from actually going over the wire. Here is an example using Moq. HttpClient depends on HttpMessageHandler’s SendAsync() method, so give SendAsync() a stub implementation and use Moq’s Callback() to ......

One of the decisions a developer needs to make while designing a class is when to use a property and when to use a method. Methods typically represent an action or an operation whereas, properties represent pieces of data associated with a class / instance. Properties are typically used to allow accessibility (getting and/or setting) to private class ......

Although both arrays and collections are used in a similar fashion, there are some performance considerations when choosing one over the other. Below are some design guidelines: 1- You should not return an internal instance of an array. This allows calling code to change the array. The following example demonstrates how the array delimiters can be altered ......

Before we proceed any further, I should say this, Testing through this public API should be your first choice.Alternative for Abstract Base Classes One common case is when an abstract base class defines functionality in some protected methods, and there are a series of inheriting classes using those methods without overriding them. In this case, rather ......

AssemblyInitialize is very similar to the ClassInitialize and TestInitialize attributes, but rather than executing before classes/methods are run it executes before the any method marked with TestMethod, ClassInitialize, or TestInitialize inside this assembly. Only one method in an assembly can be annotated with this attribute. Code that belongs in ......

Copyright © Abhishek Anand | Powered by: GeeksWithBlogs.net