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!
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.