Archives for : November2008

foreach loops

Just a quick note here on foreach loops. Not sure if you knew this but foreach loops can be used to iterate over multidimensional arrays.

Imagine you have:

int[,,] myInts = {{ { 0, 1, 2 }, { 3, 4, 5 } }, { { 0, 1, 2 }, { 3, 4, 5 } }};

you can iterate over the whole 3D array here in a single foreach:

foreach (int i in myInts)
{
    Debug.Write(i.ToString());
}

The resulting output is: 012345012345

Later,
Brian

UPDATE:
If you want to use foreach to access arrays of ints in a multidimensional array you have to declare the array as if you were declaring a jagged array. The flaw with this is that you will be unable to use foreach to access all elements of the array directly but must instead access the arrays to access the elements. Basically int[][] != int[,] as the first one is an array of arrays and the second one is a multidimensional array. I suppose it makes since if you think of arrays in C# terms as objects instead of C/C++ as memory locations.

int[][] myInts = new int[][]{ new int[]{ 0, 1, 2 }, new int[]{ 3, 4, 5, 6 } };
foreach(int[] childArray in myInts)
{
    foreach(int child in childArray)
    {
        Debug.Write(child.ToString());
    }
}
//no longer works
//foreach (int i in myInts)
//{
//    Debug.Write(i.ToString());
//}

Microsoft’s 101 LINQ samples

I wanted to let you all in on a little secret.  When I am feeling the urge to write a linq post and can’t find something write about I go to Microsoft’s 101 LINQ samples.  For the most part they’re simple examples of a lot of the features that LINQ has to offer. 

The list is not all-inclusive but it usually provides some starting point for a LINQ post.  The samples are pretty simple and there’s not a lot of explanation.  I try to take some of the samples and expand and explain them.  Also I run all samples through visual studio.  I have had some of the samples there not compile so try them out before you blindly trust them. 

Next time you see a LINQ post here don’t be suprised if it started life as a 101 LINQ sample.  I just take a simple example and then beat as much blood from it as I can.

Brian

Visual Studio 2010 and .NET Framework 4.0 CTP

I’m about to start working on a project that includes some potential .NET Framework 4.0 stuff. Dug around and found the links for downloading the ctp for Visual Studio 2010 and .NET Framework 4.0 CTP.

I haven’t downloaded it yet since we haven’t officially started the project but I’m eager to get things going :).

Post stats after one month

I have done zero real advertising about this site other then Facebook, setting up google sitemaps and mentioning it to friends. No pingbacks, trackbacks or putting up my url anywhere really. Some how, however, I managed to get 185 unique hits for the month of October. That is without my hits from the three locations I would go to it from and without any bots. That’s right, 185 people went to my website and they weren’t me!

Here is a rundown of the top 10 most popular pages. These are not unique hits but represent the total number of hits per page.

Page Number of visits
My RSS feed 6348 (wow, a lot of you added me to your rss viewer)
Home Page 1126
UpdateOrInsert (Upsert) 37
About Page 20
WPF and MousePosition 19
WPF – ContentProperty, it’s that simple 17
Assert Yourself! 13
T1, T2, T3, T4, TResult, Hut, Hut, Hike 13
xaml attach WPF – ContentProperty post 7
C# Category 6

So how did people even find the site? Well, google really. Here is a partial list of google terms that led to this site:

61 different keyphrases Number to site from Search
get mouse position to screen in wpf 6
hibernate upsert 4
formatexception 3
format exception 3
wpf contentproperty 3
cannot implicitly convert type system.linq.iorderedenumerable 2
contentproperty wpf 2
postgres insertorupdate 2
c# sql server upsert 2
upsert postgresql 2
Other phrases 53

Anyways, I’d like to have one significant post a week and one trivial post a week. As I saw with October that’s not an easy task but I think I’m up for the challenge. I don’t profess to be an expert on anything. Anywhere I might sound like an expert I try to link to a real expert. I’m just trying to pass on the knowledge I gain in the form of ramblings on developing in the Windows(tm MS i’m sure) world.

My next step is to try and generate some contriversey. I think my posts so far have been too “tutorial” in nature. I’ll try to keep those going since I have fun writing them but I think some topics intented to spawn debate need to be next. So any recommendations from those of you who stop by on a regular basis would be nice. I have allowed anonymous comments so tell me how you really feel. Of course I reserve the right to delete and edit posts as necessary but don’t let that stop you 🙂

Thanks to all of you that stop by and don’t be afraid to say, “Hi!” (and yes, i mean literally 🙂
Brian