Skip to main content

Posts

Showing posts from September, 2013

The evolution of C# Part II - Generics

This is a well discussed matter throughout the internet. Everyone knows about generics, what they do and what they are used for, right? No. There is a variety of reasons why you wouldn't know about generics, and some of them are: You are new in the language You are not new in the language but never cared to learn it Simply because you never learned the basics about generics, it doesn't mean you've never used it. If you recognize this snippet, then you are already dealing with generics: So, what is the advantage of generics? Type safety Generics will allow you to catch the errors at compile time rather than runtime by enforcing the rules of type safety that make C# a statically typed language. This leads to increased productivity because you don't have to run the code to know that something is wrong. For example, if in the snippet above you tried to add a new item of type string, a compiler exception would be thrown. Typically, in C# 1.0, you would use an...

The evolution of C# Part One - The beginning

Today, let's talk about some history. Not that World War history, but the history and evolution of C# as a language. I would like to analyze the principal parts in one of the mainstream languages of mass production in today's software. Beware that most of what i am about to say is the fruit of much research, in part because when C# and the .NET became available i had not written a single line of code yet, so you can say that i am a newborn in this world. I'm inclined to change that, though, but every new discovery is done with much enthusiasm on my part, and i'm very proactive, which sometimes may upset my colleagues. One of the reasons i'm writing this article - and this blog all the same - is because i love to learn new things and share it with others. Enough talk, let's get to the point! The beginning of .Net The .NET platform brings a brand new and fresh way of programming your applications. Microsoft created the term "Managed Code" to refer t...

A tip on strings

Today, let's look at a simple trick with strings in C#. It may be too obvious and repeated around the internet, but nevertheless i want to give my 2 cents on the subject. So, let's start! Imagine you have a list of any type and now you will need this values separated by a comma in order to be processed in some stored procedure. The desired output for a list of  {1,2,3,4} is a string like this "1,2,3,4" . How will you solve this problem? I've seen and done multiple approaches. Let's order the possible solutions (in my mind) from the most complex to the simpler. First, we can do: Notice how complex this can be, and how fast it can become messy. When replicated across an entire project (imagine the nightmare of having this replicated in your Data Access Layer whenever a stored procedure needs this input), this can be a pain. Of course, you could extract the behavior and create an extension method for it, but as we will see, it is not necessary. Our second...

Introduction

Introduction My name is Mário Constantino, i'm Portuguese and i love what i do. I work as a junior developer at a small company for 2 years-ish now. This is where i started my career, so i'm still young and have the enthusiasm that comes with the age :) Our primary area is the development of ERP software in .NET technologies interacting with SQL. This gives me a little experience, but i'm far from an expert in the area, although i'm learning a lot each day. Blogging is a new experience for me, so you'll excuse me if i make some rookie mistakes. I've been on the internet since i can remember, but only on the consumer side, never on the producer. Well, for what it's worth, now i'm going to start to produce blog posts! But first, English is not my primary language, and some typos are in order. If you catch one, please tell me in a comment. I'm Portuguese, but i thought that by making the posts in English i would get a broader audience. Also, the...