Talking about “Really Smart” Type Inference in C#3.0


As some of you may know (  if I have any readers 😉  ) I’m a frequent face in the "Linked.NET users group (Lidnug)" on Linked in (There’s a link to the left if you’d like to visit.

I recently placed a post in the discussions about the merits of complex nested arrays, v’s using Strongly typed collections, and found that one of the other regulars Isaac had a short but sweet article on his own blog that was even more elegant than my example.

If you want to take a look at the article on Linked in you can get to it by "Clicking Here" please note however, you will need a Linked-in membership, and you will need to request access to the Lidnug group

So without further ado, below is the track backed quote from Isaac’s post.

Quote

“Really Smart” Type Inference in C#3.0

At least I think that this was added in C# 3.0 – “implicitly” typed arrays.

Imagine this simple scenario:

IEnumerable <string> myStrings;

Now imagine that we wanted to assign “Isaac” and “Daniel” to that reference. We could do it in a number of ways: –

IEnumerable <string> myStrings = new List<string> { “Isaac”, “Daniel” };
 

This uses Object Initialisers which aids readability, although we’re being a bit lazy using a List<T> for such a simple collection.

more…

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s