Tips

S3 — Use using block to get the stream

When you’re using the Ama­zon S3 client, have you come across the occa­sion­al excep­tion that says some­thing like one of these excep­tion mes­sages: “The request was abort­ed: The con­nec­tion was closed unex­pect­ed­ly” “Unable to read data from the trans­port con­nec­tion: A block­ing oper­a­tion was inter­rupt­ed by a call to WSACancel­Block­ing­Call” “Unable to read data from …

S3 — Use using block to get the streamRead More »

.Net Tips — Find out if your app is running as a service

When you are devel­op­ing an appli­ca­tion to run as a ser­vice it’s nice to be able to also run it as a con­sole app so you can eas­i­ly debug, etc. On the rare occa­sion you might even want to find out if your app is run­ning in a con­sole win­dow at run­time so you can …

.Net Tips — Find out if your app is run­ning as a ser­viceRead More »

.Net Tips – Use LINQ to create pairs of adjacent elements from a collection

Sup­pose you have an array of num­bers, say, [1, 3, 5, 7, 9, …], and you want to pair each ele­ment up with its neigh­bour in the array, e.g. [[1, 3], [3, 5], [5, 7], [7, 9], …]. Sure, you can iter­ate through the indices of the ele­ments and recur­sive­ly grab the ele­ment at an …

.Net Tips – Use LINQ to cre­ate pairs of adja­cent ele­ments from a col­lec­tionRead More »

.Net Tips – Make sure the runtime types match when combining delegates

In C#, it’s pos­si­ble to com­bine two del­e­gates, A and B to cre­ate a new mul­ti­cast del­e­gate, C:   When the mul­ti­cast del­e­gate is exe­cut­ed, the com­bined del­e­gates are exe­cut­ed in order as you can see from the exam­ple above. But before you can start mix and match­ing your del­e­gates like a kid in a …

.Net Tips – Make sure the run­time types match when com­bin­ing del­e­gatesRead More »

Mind the runtime optimization

You might know this already, but in C# when­ev­er you write some­thing like this: 1: if (Metho­dA() || MethodB()) 2: { 3: // do some­thing 4: } it’s not guar­an­teed that both meth­ods will be exe­cut­ed, so DO NOT DO THIS if you’re rely­ing on both meth­ods to be expect­ed to cause some desir­able side-effects. …

Mind the run­time opti­miza­tionRead More »

Things I didn’t know about expando objects

I found out two inter­est­ing things about the ExpandoOb­ject class intro­duced in C# 4 this bank hol­i­day week­end: 1. you can spec­i­fy cus­tom events on them 2. it imple­ments the INo­ti­fyProp­er­ty­Changed inter­face Here are some quick demos to show you how to use these fea­tures: Cus­tom Events To add a cus­tom event is the same …

Things I didn’t know about expando objectsRead More »

Turn ExpandoObject into static type

As many oth­ers have shown, the new ExpandoOb­ject intro­duced in C# 4 can be pret­ty use­ful in some sce­nar­ios. How­ev­er, on the odd occa­sion when you want to con­vert an ExpandoOb­ject to a sta­t­ic type you have defined you can be for­giv­en for feel­ing a lit­tle lost as there are no well doc­u­ment­ed ways to …

Turn ExpandoOb­ject into sta­t­ic typeRead More »

.Net Tips – Working with anonymous types

Anony­mous types are use­ful, espe­cial­ly in LINQ queries where you often want to iter­ate through an array of items and project them into some arbi­trar­i­ly shaped objects that are lit­tle more than sim­ple data con­tain­ers, using anony­mous types save you the has­sle of hav­ing to first declare those types which you will sim­ply throw away …

.Net Tips – Work­ing with anony­mous typesRead More »

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close