Type conversion (or typecasting) is the technique to change an entity from one data type into another. In general there are two types of type conversion; implicit and explicit conversion. This post tells about type conversion in C#.NET and the performance issues.
Implicit conversion (or coercion) is automatic type conversion by the compiler. In C# it does not require a special syntax because the type conversion is safe and no data will be lost. In the following example the value of an integer is stored in a long. This is safe because an integer is 4 bytes (on a 32 bit computer), and a long is 8 bytes. So every value that fits in an integer fits in a long. For a complete conversion table see this page.
int i = 12345678;
long l = i;
It is also possible to cast a derived class to a base class without using a special syntax.
Continue reading Type conversion in C#
In some of my web applications I use Rhino Mocks to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the NUnit test run will fail:
Rhino.Mocks.Exceptions.ExpectationViolationException : IMyInterface.MyVoidFunction; Expected #0, Actual #1.
/* insert expectation for void function here */
// DoSomething calls the mocked object's GetValue function, which returns 'b' when the parameter is 'a'
// DoSomething also calls a void function which is located in the interface of the mocked object, so this
// void function must be mocked too, else the test run will fail
Continue reading Using Rhino Mocks to mock a void function
On my server I want to create accounts that can do SSH in a chroot environment. On the internet I searched for tools and I found Jailkit. In this post I will tell how I installed Jailkit on Ubuntu server 9.10, created a jail and how users are added to the jail. Note that most commands in this tutorial should be executed as su or sudo.
First I installed Jailkit by using the following commands:
# cd /tmp
# wget http://olivier.sessink.nl/jailkit/jailkit-2.11.tar.gz
# tar -zxvf jailkit-2.11.tar.gz
# cd jailkit-2.11
# make install
Continue reading How to create a chroot ssh user in Ubuntu
In part 1 I described the requirements and hardware for my home server. In this post I will tell about unpacking and assemblage of the home server.
Continue reading Building a home server part 2