Csharp (Page 2)

Harmful collection transformations. Part 2: automatic diagnostics Read in English

The previous post contains code examples that can be simplified by removing ToArray() or ToCharArray() calls. And an interesting example with List<char> constructor. But we need to be very attentive to find such places in our code. It would be much safer to do it automatically. This post shows us about automatic compiler diagnostics that can detect issues.

Read more...

Harmful collection transformations. Part 1: string to array of chars Read in English

An array — the simplest collection. It's just a memory block with elements of one type. Arrays are often used when we need to iterate a collection, to search for elements or transform them. C# and .net evolved, many new collections were introduced, interfaces allowed to create generalized algorithms, LINQ simplified the work of programmers, but we continue to use arrays in inappropriate places and perform excess and sometimes harmful transformations. This post begins a series about collections, their features, performance and design. All posts will contain benchmarks, code examples, my opinion and recommendations.

I want to start with a string, some specific collection of .net.

Read more...

NDepend: first overview Read in English

There are a bunch of tools that help c#-developers write code better, more performant and with a better quality. NDepend is one of them. Here is my experience of using this tool.

Read more...

ASP .NET WebApi: Model validation Read in English

You may know about ValidationAttribute. First appeared with .NET Framework 3.5 it is still used for validation. This article is about data model validation in ASP.NET WebApi.

Read more...

LINQ: Group by byte Read in English

LINQ is a powerful tool for collection (or enumeration) operating. You use functional-like syntax for filtering, grouping, transforming data. All LINQ methods work with common interface IEnumerable<T> and usually methods do not check real type of collection, or data type. Sometimes, if you know the type of collection or generic type, you can optimize code for better performance (like in Any vs Count).

This article will show, how you can speed up grouping by specific key - byte.

Read more...

LINQ: Any() vs Count Читать на русском

Эта статья началась с обсуждения на Stack Overflow: Why LINQ method Any does not check Count?. Здесь мы сравним производительность методов Any и Count != 0.

Read more...

LINQ: Any vs Count Read in English

This post started from discussion on SO: Why LINQ method Any does not check Count? This article shows a comparison of performance methods Any and Count = 0.

Read more...

Patterns: Specification Read in English

Specification pattern unites Domain-Driven Design, application architecture modeling and Entity Framework in C#. Specification pattern is designed to order business rules and connect our code to the business terms. This article shows an example of the implementation with Entity Framework.

Read more...

Xml serializer - volatile api contract Read in English

Working with some API, you expect that this API will stay stable and return the same type of result from call to call. But sometimes it does not work this way. In the article I will tell about integration with SOAP-service and volatile contracts.

Read more...

Sleep well. How to stop program execution. Read in English

How many ways to sleep a thread do you know?

Read more...