CSTrüter HomeArticlesDownloadsAbout meContact me
How to enable the filestream feature in SQL 2008 - Alternative way to store blobs(files) via SQL 2010-08-21 19:31:56
How to create a Singleton Pattern in C# 2010-08-10 22:52:52
How to prevent that threads access shared resources concurrently via Monitor. 2010-08-06 15:31:15
A quick review of the book PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide written by Larry Ullman 2010-08-04 21:48:58
How to prevent that threads access shared resources concurrently via Mutex. 2010-08-03 14:42:36
How to stop propagation of javascript events 2010-07-25 21:59:29
Post about how Pete the web developer fixed his sitemap 2010-07-17 15:12:02
How to setup an out of process session service 2010-07-08 17:51:46
How to display/add images from/to a SQL Database 2010-07-04 23:15:15
How to register a custom URL protocol handler 2010-06-28 20:34:01
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
Populate a TreeView control in a windows application. 2009-08-27 16:01:03
2007-02-22 12:00:00
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; } }
The company I am currently working for as software developer.
Collection of C# snippets 2010-05-22 01:06:19
Collection of MS SQL snippets 2010-05-22 00:55:15
Collection of JavaScript snippets 2010-05-22 00:37:57
Collection of ASP.net snippets 2010-05-22 00:29:56
Collection of PHP snippets 2010-05-22 00:06:45
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