• Uncategorized

    What null smaller than 0? Adventures with nullable types in .NET

    Lets say we have two nullable integers like this: int? i = null; int? j = 0; Is null smaller than 0 Console.WriteLine(i < j); False – no it is not. So probably null is greater than 0 Console.WriteLine(i > j); False – no it is not greater as well. All right! So null is equal 0. It has to be, JIT has no other choice, right? Console.WriteLine(i == j); Well False too! This two little fellows are not equal too. What? Is it raining frogs and we about to experience Armageddon? No! We have to use Nullable.Compare() and we will by back in normal world: switch (Nullable.Compare(i, j)) {…

  • Uncategorized

    Enum Factory

    I have a little tip for you. Let’s say you have an enumeration. You need a enumeration constant out of string variable. simply use System.Enum.Parse(). Here a small Snippet Compiler source code. using System; using System.Collections.Generic; public class MyClass { public enum FooBar { Foo, Bar, FooBar } public static void Main() { WL(FooBarFactory("Foo")); RL(); } public static FooBar FooBarFactory(string init) { try { return (FooBar)System.Enum.Parse(typeof(FooBar), init); } catch { // Do something throw; } } #region Helper methods private static void WL(object text, params object[] args) { Console.WriteLine(text.ToString(), args); } private static void RL() { Console.ReadLine(); } private static void Break() { System.Diagnostics.Debugger.Break(); } #endregion }

  • Uncategorized

    Aiding your work with Visual Studio Code Snippets

    I’ve bin writing //TODO comments in my code every time wondering what pattern have we agreed upon in our team. Was it a // TODO Recipient Priority Sender, Message or // TODO Priority Sender Recipient, Message or something else. Today I thought: who am I to remember all those dentils? Do I have something to help me with this burning problem? Well I have. The name is Visual Studio Code Snippet. It in a XML file that describes a quickly insertable text. With such XML description I will by able to write only a word “todo” in my VS and everything else will happen automagically. There will by a nicely…

  • Uncategorized

    I’m sure you don’t care…

    … but I’m very glad so I share 😉 I’ve just became a MCTS – Microsoft Certified Technology Specialist in ASP.NET. I passed the 70-536 and 70-528 (with quite good marks). Now I’m starting to learn to became Professional Developer (exam 70-547). Wish my luck!

  • Uncategorized

    Language doesn’t matter

    My father is a land-surveyor (geodesist if you will). Nowadays he uses a notebook for his field measurements, but there was a time when he used a scientific calculator. Recently he’s notebook went dead, so he wanted to move back to his Casio scientific calculator. But, ups! Not in use for a while the battery ran out and the geodetical programs are gone. So I have to type my old programs back to the small computer. I thought I’ll share one of them as a example that programming language does not matter. What matters is how you use it and how well others could use your work. So let my…

  • Uncategorized

    It’s not magic – it’s floating point math

    Please remember that 3 / 12 is not always 0.25! 😉 Take this example: int i = 3; Console.WriteLine(i / 12); You will get 0. I admit it could by a little confusing at first but I assure you, there is nothing wrong in the way JIT thinks. We dividing an integer over a… integer. What we are getting? Well, of course an integer! Is it not what you expected? How to fix this? Well the easiest way is to: int i = 3; Console.WriteLine(i / 12.0); You will get 0.25. Why? Well 12.0 is a double so the whole equation will by a double. You can check this easily…

  • Uncategorized

    The power of image – merging in SVN

    I’ve recently read a short explanation of joining in SQL. I was simply amazed how ease it was to explain fairly complicated matter with few well chosen pictures. Please read it, no matter how good are you in SQL – it will surely help you next time you will have to explain joining in SQL to someone else. I’ve decided to try the same way to taking SVN branching and merging as a target. To remind you. When you are using the source control system like Subversion (SVN) you can always branch. Meaning you can take a copy of your current sandbox and check it in as a new “path…

  • Uncategorized

    IProgrammable goes multilanguage

    Dobra bez żartów. Właśnie zainstalowałem plugin do WordPress o nazwie Gengo i sprawdzam jak na IProgrammable wyglądają polskie ogonki. Żeby nie zostawiać was z bezsensownym postem testowym rzucę trochę treści. Przytoczę wam małą anegdotę. Uczestniczę w moim pierwszym kursie programistycznym Microsoftu. Prowadzący najwyraźniej programistą .NET nie jest ale myślę sobie będzie dobrze. W końcu prowadzący przede wszystkim powinien być dydaktykiem i porządnie przekazać mi wiedz, ze którą moja firma płaci prawie trzy tysiące złotych. Prowadzący pyta: – A wiedzą państwo jak w C# tworzy się parametry opcjonalne? Ki czort, myślę sobie. Nigdy o czymś takim w .NET nie słyszałem i próbuję naiwnie: – Nie wiem ale spróbowałbym polimorfizmem. – A…

  • Uncategorized

    C# 3.0 – .NET Framework ?

    I’ve written an article about C# 3.0 for a polish programmers magazine Software Developer’s Journal. That’s not my first article but the first one to hit the cover and by the issue lead. Great, right? Well I’m afraid not! Why? Because of embarrassing mistake on the cover: C# 3.0 has nothing to do with .NET Framework 3.0. The new C# version will by introduced with .NET Framework 3.0 that comes with new Visual Studio 2008. The third version of framework is essentially the same with the second but enriched with a bunch of foundations (WPF, WCF, WWF). This information appears in the first paragraph of my text! I’ll ask the editorial…

  • Uncategorized

    Who needs DBNull?

    I’m currently taking part in my first MS certified .NET training. I’ll write some more about this training after it’s over, but now I have to share one thing with you. Once again I notices that DBNull is causing more confusion than it is worth. A certified .NET instructor had a hard time describing it to course attendees. Some time ago I had a long conversation about it. Both time I couldn’t help my self thinking: “who to hell needs this DBNull”. Because in .NET DBNull is not equal null. DBNull is a little extraordinary data type. It is used to describe a value from DB that does not exists…