1. Home
  2. Computing & Technology
  3. C / C++ / C#

Latest Programming Tutorials

About C, C++ and C# brings you the latest programming tutorials, a part work built up week by week. Choose C, C++ or C# or all three.

Latest Programming Tutorials

David's C / C++ / C# Blog

A Silly C# Programming Puzzle!

Wednesday August 20, 2008
August is regarded as the silly season in the UK so here is a silly programming puzzle. What does this short bit of C# code do? Will it compile and/or run? Can you debug it?

# define i
using System;
using System.Text;

namespace ex11
{
    class Program
    {
        static void Main(string[] args)
        {

           int i = 8;
        # line hidden
            ++i;
        # line 5
        # pragma disable
        # warning reverse execution is noitucexe
        # line 4
        # line 12
            System.Console.WriteLine("i = {0}", i) ;
        }
    }
}

Answer tomorrow!

MyGeneration - Open Source C# O/R Mapping

Tuesday August 19, 2008
I really love open source (yes I know that the iPhone and open source are incompatible- sad really) and some of the projects around are quite remarkable. I've been looking at MyGeneration which is a C# open source Code Generator and O/R (Object Relational) Mapper. This is working with data held in databases with an object wrapper around them. The idea is that the relational database tables are not accessed directly or through SQL but instead mapped onto classes which simplify the use of the database.

The code generator takes the tables for a wide variety of databases (12!) and produces the class code. It's template driven (not C++ type templates) so the code generator can output code for JScript, VBScript, C# or VB.NET. It's worth a look not just because it's open source but because of the architecture. This is what the C# looks like for accessing an employee record. (This code example is similar to one on the MyGeneration website).

Employees emps = new Employees() ;
if(emps.LoadByPrimaryKey(31))
{
    emps.LastName = "Bowman";
    emps.Save() ;
}

// Add one new record for Mr Archer
Employees emps = new Employees() ;
emps.AddNew() ;
emps.FirstName = "Mr.";
emps.LastName = "Archer";
emps.Save() ;

// get the last record index
int i = emps.EmployeeID;

Not a sql statement in sight! You'll find mygeneration here and the code on sourceforge. Note, you'll need another sourceforge project- the free 7z archive utility to extract the source code files.

Explore C / C++ / C#

More from About.com

  1. Home
  2. Computing & Technology
  3. C / C++ / C#

©2008 About.com, a part of The New York Times Company.

All rights reserved.