CSTrüter HomeArticlesDownloadsAbout meContact me
a quick look at how to create a windows service using C# 2010-02-28 21:48:06
How to call server-side code from client-side code, using PageMethods in ASP.net 2010-02-21 12:31:27
How to pass a set of data to an xml type in SQL 2005/8 2010-02-12 19:04:23
Some funky behaviour regarding overload Resolution of dynamic/object types 2010-02-09 17:16:52
Object orientated programming within JavaScript 2010-01-28 07:25:45
How to sort data using ASP.net (C#) and SQL 2005/8 2010-01-18 15:23:14
Quick look at some of the new features added to C# 4.0 2010-01-12 21:52:13
SQL 2008 introduced a nifty feature called Table-Valued Parameters (TVP) into its codebase 2010-01-06 22:58:25
How to page data using ASP.net (C#) and SQL 2005/8 2009-10-19 15:01:45
a post about sql joins 2009-09-20 15:50:57
Creating a WYSIWYG textbox for your website is actually quite simple. 2007-02-01 12:00:00
Move items between two listboxes in ASP.net(C#, VB.NET) and PHP 2008-06-12 17:07:43
Firefox word wrapping issues 2008-06-09 09:51:21
2007-02-22 12:00:00
Blog about passing parameters by reference to functions using func_get_arg(s) 2008-07-27 12:38:24
The 1st of Jan 2010 I installed Visual C# 2010 Express, quite appropriate date don't you think? (Delayed thanks to my lack of bandwidth among other things, but don't let me get started on that one, sigh) I know at this point I am a few million years behind writing on this subject, but hey, better late than never. Nevertheless, I've been having some fun playing around and reading up on all the wonderous new features for a while now - new to C# at least. The focus of this release (version 4.0), is "Dynamic Programming", which is somewhat code word for "We're compromising to fit/interact with other Tom, Dick & Harry languages". (You guys know who you are) The new features can be broken up in four groups: Dynamic lookup Allows developers to bypass static type checking (eg dynamic typing), resolution of dynamic types happen during runtime - finally giving C# variables an identity crises ;) :P (Who am I?) dynamic a = "Dude"; // I am string a = 10; // No, wait I am an int a = DateTime.Now; // Oh, now I am a date I suspect this is going to become quite the misused feature over the next few years. Its great for late-binding and will minimize the amount of code needed in certain cases (eg Type casting) - but potentially quite frivolous. Named and optional parameters Allows developers to specify optional parameters, by giving them default values ( similar to VB, PHP, SQL etc) // Notice the optional parameters static void test(Int32 i, String s1 = "Test1", String s2 = "Test2") { Console.WriteLine(i); Console.WriteLine(s1); Console.WriteLine(s2); } static void Main(string[] args) { // Excluding optional parameters test(1); // Notice s2, a named parameter test(1, s2: "Test4"); } COM specific interop features Dynamic types, named and optional parameters will greatly improve interaction with COM, what is more bloated Primary Interop Assemblies (eg Office Integration), wont be needed anymore, instead only needed functionality will be included into the referencing assembly. Remember the following? If you've worked with office automation for example, it will look all too familiar... object missing = Missing.Value; object newfilename = "a.docx"; document.SaveAs(ref newfilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing); If you've ever attempted this in VBA, you'd remember it being a lot cleaner, this is what we see using C# 4.0: document.SaveAs("a.docx"); Variance C# 4.0 will support safe covariance (allow more derived return type) /contravariance (allow less derived parameter types) via interfaces & delegates. Have a look at the following quick example (using delegates), notice the out/in keywords and how they're being used. using System; using System.Collections.Generic; using System.Linq; using System.Text; class a { } class b : a { } delegate T covariance<out T>(); delegate void contravariance<in T>(T value); class Program { static void Main(string[] args) { covariance<b> _b = () => new b(); covariance<a> _a = _b; contravariance<a> _a1 = (param) => { Console.WriteLine(param); }; contravariance<b> _b1 = _a1; } }
dynamic a = "Dude"; // I am string a = 10; // No, wait I am an int a = DateTime.Now; // Oh, now I am a date
// Notice the optional parameters static void test(Int32 i, String s1 = "Test1", String s2 = "Test2") { Console.WriteLine(i); Console.WriteLine(s1); Console.WriteLine(s2); } static void Main(string[] args) { // Excluding optional parameters test(1); // Notice s2, a named parameter test(1, s2: "Test4"); }
object missing = Missing.Value; object newfilename = "a.docx"; document.SaveAs(ref newfilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
document.SaveAs("a.docx");
using System; using System.Collections.Generic; using System.Linq; using System.Text; class a { } class b : a { } delegate T covariance<out T>(); delegate void contravariance<in T>(T value); class Program { static void Main(string[] args) { covariance<b> _b = () => new b(); covariance<a> _a = _b; contravariance<a> _a1 = (param) => { Console.WriteLine(param); }; contravariance<b> _b1 = _a1; } }
Codebooth my semi-community site etc (work in progress)
The company I'am currently working for as software developer.
a Parallel reference of programming languages 2009-09-10 12:48:23
a tutorial explaining how to develop a simple login using PHP and MySQL 2009-09-05 18:26:47
An article looking at adding some kind of event driven model to PHP 5 2008-07-28 12:48:09
It is very simple creating your own rss reader, the following article looks at a few methods of doing this. 2008-06-23 13:18:25
A quick reference about working with dropdown boxes (select element) in javascript. 2007-02-17 16:36:41
Collection of funny programming articles 2006-10-08 14:23:43