LA.NET [EN]

May, 2011Archive

May 31

.NET and nullable value types – part III

Posted in Uncategorized       Comments Off on .NET and nullable value types – part III

As you’ve probably noticed, I’ve been a little busy with my new cat. Besides that, I’ve also caught a cold and I’m still lagging in my last work project. Nonetheless, I need to relax and I guess that writing another post on the .NET and nullable value type series is a good way to let […]

Read the rest of this entry »

May 29

Say hello to Irina

Posted in Trivia       Comments Off on Say hello to Irina

Irina is a lovely cat which we’ve picked up from the street. She’s already one year old and I couldn’t resist seeing this beautiful cat abandoned. She arrived last week and I believe she really loves her new home.

Read the rest of this entry »

May 25

.Net and nullable value types – part II

Posted in .NET, Basics, C#       Comments Off on .Net and nullable value types – part II

In the previous post, I’ve introduced the concept of nullable value types. As I’ve said back then, C# allows us to use a simplified syntax for working with nullable value types: Int32? aux = 10; Int32? aux2 = null; Console.WriteLine("aux, has value: {0}, value: {1}", aux.HasValue, aux.Value); Console.WriteLine("aux2, has value: {0}, value: {1}", aux2.HasValue, aux2.GetValueOrDefault()); […]

Read the rest of this entry »

May 25

As I’ve said, a variable holding a value type value can never be null. The justification for this behavior is obvious: the variable contains the value itself (unlike reference types, where the variable holds a reference to another memory location in the heap). And life was fine until someone noticed that it would be really […]

Read the rest of this entry »

May 24

I’m proud to say that my latest book is out! This time, I’ve decided to write about JavaScript and I tried to cover most features associated with its use. Notice that this isn’t a DHTML book. Instead, I tried to present all the features of this language (including the new ones introduced by ECMAScript5) and […]

Read the rest of this entry »

May 24

Arrays in .NET– part VII

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET– part VII

To wrap up this series on .NET arrays, I’ll show you how to create a fixed size buffer (aka internal arrays). A fixed size buffer is useful technique for improving the performance of your app when you need to interop with unmanaged code. To understand the gains from this approach, we’ll start with a simple […]

Read the rest of this entry »

May 22

Arrays in .NET– part VI

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET– part VI

I’ve ended the previous post saying that there was still one extra mile we could take to improve the performance associated with arrays in .NET. This extra mile has a name: stackalloc. The stackalloc keyword can only be used in unsafe code and it’s responsible for allocating a block of memory on the stack. In […]

Read the rest of this entry »

May 22

Arrays in .NET–part V

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET–part V

In the previous post, we’ve looked an non-zero based arrays and I’ve ended the post by talking a little bit about performance. As I’ve said, non-zero based arrays are not really something you want to use regularly. Besides that, we’ve also seen that regular arrays aren’t as performant as jagged arrays because the compiler won’t, […]

Read the rest of this entry »

May 20

Arrays in .NET – part IV

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET – part IV

Today I’m going to to something which I really don’t like: I’m going to show you how to create non-zero lower bound arrays (aka, non-zero-based arrays). Before going on, I must say that I find it hard to justify the creation of these types of arrays. Anyways, since I’m covering arrays, I guess I must […]

Read the rest of this entry »

May 19

Arrays in .NET – part III

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET – part III

Now that you know the types of arrays you can create and how to simplify its initialization, it’s time to see what we can do with then. As I’ve said previously, all arrays inherit from the base Array type. In practice, this means that all array instances we create inherit automatically all the properties and […]

Read the rest of this entry »

May 19

Arrays in .NET – part II

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET – part II

In the first post of the series, I’ve talked about the several types of arrays you can define on your .NET apps. What I didn’t mention at the time is that C# allows you to create and initialize an array with a single instruction: var ints = new Int32[] {1, 2, 3}; When the compiler […]

Read the rest of this entry »

May 19

Cultures, cultures and still more cultures…

Posted in .NET, Basics, C#       Comments Off on Cultures, cultures and still more cultures…

In one of my latest’s post on text and strings, reader John Meyer asks a couple of interesting questions: Can you discuss any differences between these 2 ways of getting CultureInfo objects? var culture1 = new CultureInfo(“en-US”);var culture2 = CultureInfo.GetCultureInfo(“en-US”); left one out of the previous comment, sorry: var culture3 = CultureInfo.CreateSpecificCulture(“en-US”); Before answering the […]

Read the rest of this entry »

May 18

Arrays in .NET – part I

Posted in .NET, Basics, C#       Comments Off on Arrays in .NET – part I

Currently, the CLR supports single-dimension arrays, multi-dimension arrays and jagged arrays (aka, arrays of arrays). Arrays are always implicitly derived from the Array reference type.Creating a single-dimension array is simple, as you can see from the next snippet: var ints = new Int32[10]; ints references an array which can hold 10  Int32 elements (ie, 10 […]

Read the rest of this entry »

May 18

Zebra code again…

Posted in C#       Comments Off on Zebra code again…

After I’ve posted my initial code, I’ve went ahead and I’ve done some refactoring so that it would also support some of the ZPL commands (here’s the code). Notice that this isn’t really the latest version (you’re probably looking at a version which has, at least, 4 years) of the project but it has enough […]

Read the rest of this entry »

May 17

So, you know everything about text, right? – part XV

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right? – part XV

In the previous posts, we took a deep dive into how we can format objects into strings. In this post, we’ll see how to obtain an object from a string (a process known as parsing). By convention, all the types that can parse a string offer a static method named Parse which (at a minimum) […]

Read the rest of this entry »

May 16

In the previous post, we’ve looked at the specificities associated with the usage of the IFormattable interface. As we’ve seen, its ToString method expects a format string and an IFormatProvider instance which allows any interested party to get a reference to an object that can be used for formatting and parsing (more on this in […]

Read the rest of this entry »

May 16

So, you know everything about text, right? – part XIII

Posted in Uncategorized       Comments Off on So, you know everything about text, right? – part XIII

In the previous post, I’ve mentioned that I’d dedicate a post on the topic of formatting. And I thing the best way to start the discussion is to start by looking at the ToString instance method. The ToString is a public and virtual method introduced by the Object class. In practice, this means that it […]

Read the rest of this entry »

May 16

So, you know everything about text, right? – part XII

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right? – part XII

Even though I’ve said that the previous post would wrap up this series, the truth is that there are still a couple of things I’d like to add in this text. Today, I’ll talk a little bit about the String.Format method which allows us to build strings from many formatted objects. Lets start with a […]

Read the rest of this entry »

May 13

So, you know everything about text, right? – part XI

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right? – part XI

To wrap up this series of posts about text, we’ll talk about best pratices for handling string concatenations. Since string objects are immutable, concatenating lots and lots of strings might be really bad for the performance of your application. Before going on, it’s important to understand that string concatenation *might* only be problematic at runtime. […]

Read the rest of this entry »

May 12

So, you know everything about text, right?–part X

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right?–part X

This is becoming a large series on strings…the good news is that there are still several interesting things to say about them, so this will be another “text post”. Today, we’ll take a quick look at how we can secure a string. As you know, there are lots of times where a string contains sensitive […]

Read the rest of this entry »

May 12

After hearing lots of good things about EF 4.1 and its new code first approach, I’ve decided to take a look to see if it’s as good as they say. I must admit: the latest version has lots of good things, but it still is far far away from my favorite ORM (which, btw, is […]

Read the rest of this entry »

May 12

In the previous post, we’ve started looking at encodings. In this post, we’ll finally put those theoretical concepts in practice and we’ll take a look at some code. Let’s start with a simple example. Suppose you’re building an application which will only handle English Strings. In this case, you know that UTF-8 will probably be […]

Read the rest of this entry »

May 03

So, you know everything about text, right?–part VIII

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right?–part VIII

As we’ve seen, all chars are represented by 16 bit Unicode values. If you’re a win 32 programmer and you’ve been lucky enough to go “managed”, then I bet nobody is as happy as you because this means that you no longer have to write that lovely code for converting between MBCS and Unicode, right? […]

Read the rest of this entry »

May 02

So, you know everything about text, right?–part VII

Posted in .NET, Basics, C#       Comments Off on So, you know everything about text, right?–part VII

If you’re a reader of this blog, then you probably know that I’m Portuguese. Aside from accentuated chars and the notorious ç, there really aren’t any issues associated with the fact that .NET stores chars in 16 bits memory spaces. In other words, I’m a lucky bastard   Before going on, a disclaimer: generally, I […]

Read the rest of this entry »