December 8th, 2008
.NET 2.0 added the NetworkInformation namespace which allow you to discover and query all the network interfaces in the local machine. The information this provides is very similar to what you can find by opening the “Network Connections” in Windows. In this post I have a look into the kinds information it provides — and what to look out for if your code has to run on Mono as well.
Read the rest of this entry »
Tags: Learn C#, network
Posted in Beginner, Learn C# | No Comments, yet!
December 8th, 2008
A common problem is the find out the IP address of the machine your C# program is running on. C# provides two methods for obtaining the information. The first one is easy; but somewhat undocumented. The other one is just a little harder. If your code has to run on Mono then the second option is your only alternative.
Read the rest of this entry »
Tags: Learn C#, local ip
Posted in Beginner, Learn C# | 1 Comment already!»
November 27th, 2008

Unit testing helps you verify that each individual part of your code is working as expected and keeps doing that as you change your software. You do this by adding small bits of testing code and have the unit testing frame work execute them in order. I am currently writing some code that needs to have a basic unit testing framework and wanted to install the NUnit framework. This post is about how you can install NUnit, use it and run it with / install it for Visual Studio C# 2008 Express. I will leave the nuts and bolts of unit testing to a future post but this post should get you up and running.
Read the rest of this entry »
Tags: nunit, unit testing, visual studio express C# 2008
Posted in Intermediate, Learn C# | 10 Comments - getting there! »
November 26th, 2008

In the dark ages before the Internet there was “war-dialing”: randomly calling telephone numbers in the hope that on the other side a computer modem would pick up. War Dialing was glamorized by the movie “Wargames” but portscanning is just like that: you too can help the world narrowly avoid nuclear Armageddon. This article shows how you can build a simple Portscanner in C#.
Read the rest of this entry »
Tags: Learn C#, portscanner, tcpclient
Posted in Beginner, Learn C# | No Comments, yet!
November 26th, 2008

If you are using TCP/IP connections in your C# application you will need to look up DNS addresses. The following article shows how you can convert an IP address to a hostname, and a hostname to an IP address. Other common uses are to find the hostname address of the local machine, and all its IP addresses — each of which we will show in the examples below.
Read the rest of this entry »
Tags: dns, hostname, ip address, Learn C#
Posted in Beginner, Learn C# | 1 Comment already!»
November 25th, 2008
![Encoding and Converting C# strings into Byte[] byte arrays](http://www.dijksterhuis.org/wp-content/uploads/2008/11/byte.jpg)
When working with io streams (such when sending and receiving information from a NetworkStream) you often have to convert C# strings into Byte[] (byte arrays) and back again. At this point it is important to consider how you would like to encode your string. This post shows how you can pass a string to a method that only accepts byte arrays — and how you can turn byte arrays back into strings again.
Read the rest of this entry »
Tags: byte, byte array, converting, string
Posted in Beginner, Learn C# | 3 Comments - getting there! »
November 24th, 2008

One wrong move and your dead, or at least your computer. Nothing is more nerve wracking than manipulating the Windows Registry. In the following example we show how you can (safely!) create your own little part of the registry and store and retrieve your applications configuration. Which is a nice way to store user names, passwords and anything else that you fancy.
Read the rest of this entry »
Tags: Learn C#, registry, windows
Posted in Beginner, Learn C# | No Comments, yet!
November 21st, 2008

Sometimes its handy to set an alarm clock — to tell you when to get that next cup of coffee for example. Your C# programs also might want to check that everything is going smoothly. Timers are handy if you want to check for example whether that download has stalled, a message needs to be send or a file needs to be updated.
Read the rest of this entry »
Tags: keypressed, Learn C#, System.Timers
Posted in Beginner, Learn C# | No Comments, yet!
November 21st, 2008

Semaphores allow us to synchronize threads inside a C# application. Semaphores are not used to transfer large amounts of data as are pipe’s or queues, instead they are intended to let multiple threads synchronize their actions. Typically you will have some kind of resource that only one , or a limited number of threads are allowed to access simultaneously.
Read the rest of this entry »
Tags: Learn C#, semaphores
Posted in Beginner, Learn C# | 2 Comments - getting there! »
November 20th, 2008

Communication between different threads in a process is trivial as they share the same objects in memory. But what if you would like to communicate with a different process (program) on the same computer? You could open a TCP/IP port to share data but the added overhead of this would slow down your program if you send a lot of data.
Read the rest of this entry »
Tags: Learn C#, named pipes, windows
Posted in Beginner, Learn C# | 1 Comment already!»