Blog Stats
  • Posts - 157
  • Articles - 0
  • Comments - 90
  • Trackbacks - 19

 

C#

When to use a switch statement/if statement?

Today someone asked me if I had told developer X that having a lot of if statements was better than a having a switch statement. I guess that developer X misunderstood what I told him a couple of weeks ago.I told him that if you have only 2 conditions that you need to check you can consider using an if statement. If you have more than 2 conditions use a switch statement instead and if you have more than 5 conditions then you should reconsider your design and make use of the command pattern or make...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Spot the issue

While continuing my review adventures I encountered the following lines of code (I replaced the names of the objects): Hashtable myHash = new Hashtable(); myHash = Foo.GetHash(); Can you spot the issue? One hint: GC. Cross-posted from The .NET Aficionado...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Spot the bug

Today I was reviewing some code. Now who can spot the exception that can be thrown in the finally block? I will give you a couple of hints: To prevent exceptions from being thrown the Open-Closed principle needs to be violated The second hint is directly related to the solution: RTTI using(IDbTransaction transaction = connection.BeginTransaction... { IDbDataAdapter dataAdapter = null; try { dataAdapter = CreateDataAdapter(); dataAdapter.UpdateCommand = updateCommand; dataAdapter.UpdateCommand.C...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

A few words on C# real literals

decimal discount = 123.5m;In the above code we set the literal value 123.5 to the variable discount. A literal value is a source code representation of a value. Beacuse it is suffixed with m we know that it is a real literal which are used to write values of types float, double and decimal. The suffix m is called a real-type-suffix. There the literal 123.5m represents a decimal type.In the above example if we would have omitted the m real-type suffix the conversion would not possible since the literal...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Help needed: Master Server Query protocol definitions and more resources

A couple of days ago I have started the plans to work on a library completely written in C# (2.0) that ultimately can be used to create clients that will query Game Servers and retrieve player information. At the moment I am gathering all the information I will need including protocol definitions.In the first version I will mainly focus on games using the Half-Life, Doom3 and Quake engines. With this library it should be easy to create for example a Gadget that will show you which players are playing...
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

 

 

Copyright © Gabriel Lozano-Morán