Friday, October 30, 2009

.Net Reference vs. Value types

In .net classes are reference types whereas structs are value types.

What this means is that if you copy a class variable to another class variable it will copy the address only. Because of this after the assignment if you change data in one variable the data change will be noticed in the second variable (which points to the same instance) as well.

Here's a short demo:

namespace referencetest

    public struct TestValueType
        public int x;
        public TestValueType(int thevalue)
            x = thevalue;

    public class TestReferenceType
        public int x;
        public TestReferenceType(int thevalue)
            x = thevalue;

    class Program

        static void ValueWithoutRef(TestValueType test)
            test.x = 20;
        static void ReferenceWithoutRef(TestReferenceType test)
            test.x = 20;

        static void Main(string[] args)

            TestValueType valueTypeA = new TestValueType(0);
            TestValueType valueTypeB = valueTypeA;
            //Since A/B is a value types
            //Changes in functions or in one variable do not affect any other copies
            Console.WriteLine(valueTypeA.x); //output 0
            valueTypeA.x = 10;          
            Console.WriteLine(valueTypeB.x); //output 0

            TestReferenceType referenceTypeA = new TestReferenceType(0);
            TestReferenceType referenceTypeB = referenceTypeA;
            //Value of A being changed Withtout a ref function
            //Causes value of B to be changed
            //since they point to the same data
            Console.WriteLine(referenceTypeB.x); //output 20


The output :

Thursday, October 22, 2009

How to export all the SQL DDL in an SQL Server database

Once you have a project ready you need to deploy it. What you need is all the data definitions (tables / view / trigger etc.) but not the data since that was probably only for testing.
Here's how to do it in SQL Server 2008.
Launch SSMS. Right click your database and select Generate Scripts as shown:

Just follow the Script Wizard. Be sure to select script all objects in the database option:

That is it. I prefer to export it to a new query window:

And then fine tune the output ... but thats just me.

Sunday, October 18, 2009

.NET Embedding scripting in your application

Three primary solutions come to mind:
  • Using the good old Microsoft Script Control. My concern with that is simply the fact that I its VBA.
  • Use IronPython. Like it A LOT.
  • Use BOO.!.aspx  Love IT!

Somehow after 4 years of it being around, BOO is still known to the cutting edge guys only. But I truly and deeply love it. I love the duck typing ... the python lists .... and yet the COMPLETE Intellisense and the Ability to import boo based modules into your C# code.  So if you intend to add an interactive debugger / designer with your application go with boo. It will be easier. But due to BOO's lesser used nature use IronPython if official support is important to you.

Inshort :
I will go with IronPython if short on time and effort.
But do BOO if I get some more time purely for the scripting engine. And make an amazing embeddable version of sharpdevelop for my application ;).

Thursday, October 8, 2009

Create a windows shortcut for shutdown , restart and hibernate

You can create a shortcut give the shutdown program commands to shutdown / restart or the rundll program to call a WIN API function for hibernation:

SHUTDOWN -s -t 01

SHUTDOWN -r -t 01

rundll32.exe PowrProf.dll, SetSuspendState

Enjoy :)

Wednesday, October 7, 2009

Best Mini PC games site

Just came across this :

An amazing site for reviews of games that can run on netbook :) (generally!)