I've been banging .NET 3.5 lately and this rendezvouz with LINQ (Language Integrated Query) has been making my brain smile alot. I mean, how can you not like something so easy and well defined and makes your life as developer alot easier.
Anyhow, I just wanted to post my LINQ cheat sheet. It's not much and it's not even complete yet (I call this part 1.1). It consist of a few snippets that you might commonly do when doing LINQ processing. I'm planning to update this and hopefully I could find time this week to add some more piece of code that would demonstrate the other LINQ topics that I missed.
Anyway, here's some LINQ snippets:
//create our PersonService object PersonService ps = new PersonService();
//get the list of person PersonList listOfPerson = ps.GetPersonList();
//get a list of people with Gender set to Male var maleOnlyList = from l in listOfPerson where l.Gender == Gender.Male select l;
//get a list of people with Gender set to female //and declaring the returned fields var femaleOnlyList = from l in listOfPerson where l.Gender == Gender.Female select new { l.PersonID, l.FirstName, l.MiddleName, l.LastName, l.Email, l.BirthDate, l.Gender, l.DateCreated };
//specify age int selectedAge = 25; //get a list of people with age greater than 25 var ageIsGreaterThan25 = from l in listOfPerson where l.BirthDate >= DateTime.Now.AddYears(-selectedAge) select l;
//get a list of people with a birthdate between a specified range var birthdateBetweenRange = from l in listOfPerson where l.BirthDate >= DateTime.Parse("1/1/1980") && l.BirthDate <= DateTime.Parse("1/1/1981") select l;
//order the result by lastname var orderByLastNameSimple = from l in listOfPerson orderby l.LastName select l;
//order the list by birthdate and lastname var orderByMultiple = from l in listOfPerson orderby l.BirthDate descending, l.LastName ascending select l;
//take three records var takeThree = listOfPerson.Take(3);
//go to the 10th record and then take 3 records from there var skipTenTakeThree = listOfPerson.Skip(10).Take(3);
//skip up until the Lastname is not equal to Thornton var skipWhile = listOfPerson.SkipWhile(n => n.LastName != "Thornton");
P.S: There's more LINQ examples at the MSDN website.
Wow, NBA.com is now joining the silverlight bandwagon.
NEW YORK — Dec. 10, 2007 — The National Basketball Association (NBA) will employ Microsoft Silverlight on NBA.com to further enhance the online video experience for NBA fans around the world. Microsoft Silverlight, a cross-browser, multiplatform plug-in for delivering the next generation of media experiences and rich interactive applications for the Web, will also be utilized on WNBA.com and NBADevelopmentLeague.com.
NBA.com will feature a full-screen NBA photo gallery, offer video highlights and deliver additional interactive applications throughout the site using Microsoft Silverlight. Through the use of Microsoft Corp.’s new application, the NBA will be able to provide further access to its extensive digital video library, integrate the video experience seamlessly into the site, and ultimately provide fans with access to more online video features.
Read the full article here...
I'm a big NBA fan and i frequently visit the site (atleast 4 times a day). Basketball is one of the most popular sports in the world and this partnership I think would greatly boost the adoption of Silverlight in the mainstream.
One more reason why i should kick my gears up another notch with silverlight.
I saw this on MSN today...
Surrogate Mothers: Womb for Rent
Customer service, tech support...these days we outsource everything to India. So why not pregnancy? Here is a report on the growing number of Indian women willing to carry an American child.
Woah...
I just saw this from my URL reffer list and it made me laugh.

Heheheh! How do you expect to get a result from this? Does the person expect to automatically get a list of all the people who attended the wedding?
I wrote an article a few years ago using SQL SMO and just realized today that I can also list SQL Severs without importing an additional assembly to my project(Microsoft.SqlServer.Management.Smo) by using the SqlDataSourceEnumerator class. SqlDataSourceEnumerator is a class that provides a mechanism for enumerating all intances of SQL Server in a given network. SqlDataSourceEnumerator exposes a method called GetDataSources() that returns a DataTable containing the list of SQL Servers and some basic information about the server
A few days ago in Twitterland, Tim Heuer had a contest. He said that whoever twitts him first would get a Microsoft Vista and Ofiice 2007 Ultimate... I quickly sent him a twit but sadly me efforts fell short. My friend Jon Galloway beat me by a second and he officially won... Jon feeling the pain of my defeat sent me a message saying that I can have the prize because he already have an MSDN subscription. Sweet!
Oh boy! That made my day!
Just today I got an email from Tim telling me that he already sent me the package and my eyes got big because it has some extras include in it.
"package en route: DHL Tracking #248211XXXXX Sent 12/07/07 to Keith Rull includes: Vista Ultimate, Office Ultimate, Expression Studio and VS2008 Pro as well as some stickers."
Wooohoooh! That's what I call Microsoft Lovin'! Thanks Tim and Jon! Now my Christmas list is almost complete... hmmm.. I wonder who's going to give me a Zune and an XBOX. :)
Now, onwards to SilverLight!
*update* [20071211]: I got the package from Tim yesterday :) Awesome! Now I don't have any excuse to neglect WPF. Thanks Tim!
...and it has pure Ruby goodness tied into it! I think I'm going to wash my .NET hands today with Neatbens SOAp enhancements. Congratulations to the great folks from NetBeans! You definetely nailed it this time.
From their official press release:
The focus of NetBeans IDE 6.0 is superior developer productivity with a smarter, faster editor, and the integration of all NetBeans products into one IDE. NetBeans IDE 6.0 features Ruby/JRuby/Ruby on Rails support, enhancements for improved Swing development, a new Visual Game Designer, updated Data Binding support, integrated Profiling, and more. The new installer lets you customize your download preferences--use it to choose the features and runtimes you need. Highlights of NetBeans IDE 6.0 are:
Java * Swing GUI Builder * Intelligent Editor * Profiler * Debugger * Updated Platform APIs
C/C++ * C/C++ Projects and Templates * Source Code Editor * Multiple Configurations * Class Hierarchy Browser * File Navigation Ruby * Ruby on Rails Support * JRuby Runtime * Code Completion * Debugger * Refactoring Mobility * Game Builder * Device Fragmentation * SVG Graphics * Web Services * Handheld Device / Set Top Box Web & Java EE * Visual JSF Design * Enhanced JavaScript * AJAX Enabled Components * CSS Editor * Web Services & SOA SOA * XML Schema Editor, XSLT Designer * WSDL Designer * BPEL Designer * Service Assembly Editor * Deploy to JBI compliant runtime
Awesome! Really awesome! I've been using Netbeans on the side(due to my obedience with .NET) and it has been a great experience for me. I have used Java IDEs in the past(Visual Cafe 4 anyone?) and i must say that Netbeans has come along way since the days of old when Eclipse elitist call Netbeans a "a tool for non-serious java developers". I think this release has proven that NetBeans is valid alternative against the big boys(Eclipse & IntelliJ among others).
Now, onwards to a cup of Java. ;)
I was working on a report today when I opened my Excel 2007 and this is all i got:

To my surprise there was no toolbar. No menu. No spreadsheet tab. Nothing. All i got was a window with the manification option showing on top of the form. I right-clicked on the bar and this is what i got:

What in the world happened? This was working fine a few days ago! Arrrgh! :( Good thing there is Google Spreadsheet handy!
I'm still a big fan of VB.NET even if I haven't touched a single VB.NET code in a year and one the biggest VB.NET fanboy I know has just started a website all about the good things you can do with VB.NET. Chris Williams (VB.NET MVP) has just started a website called ILoveVB.NET. The idea is to build a community that would champion the cause of VB.NET(which is to make the world known that VB.NET is a first class programming language and not a code kiddies toy anymore).
Here's the official message from Chris Williams:
This is the place where we show off all the amazingly cool stuff you can do with VB.NET.
If you're passionate about VB.NET, or you have an interesting project or maybe you're providing community support to a technology that doesn't currently have language parity, then you've come to the right place. We will gladly host your project and blog(s).
If you're looking for answers, you may find them here as well. If you're tired of looking everywhere for code samples and only finding C#, keep checking back here. We're making contact with the product teams and working towards getting the samples and SDKs you want.
Once again, thank you for stopping by. If you need anything, feel free to ask.
Chris Williams
Man, I bet you Paul, Carl, Bill and the VB.NET MVPs are going to be excited about this!
Somebody sent me an email today asking me about an article I wrote a few years ago detailing how to generate random strings and numbers in C# and VB.NET. He asked me if I could add function to the code that creates a random character set to be used as a base for the allowed characters in the random string. I went on and hammered the solution and this what I built for him. I don't have enough time to explain the whole thing but I hope the code comments I added would be good enough to understand what I did with the code.
[----------------- C# Version -----------------]
using System; using System.Collections.Generic; using System.Text;
namespace KeithRull.ConsoleCentral { class RandomStrings { //our default string size private const int CONST_MaxStringLenght = 10;
//our default character string set private const string CONST_AllowedCharacterLiterals = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
//our randomizer Random randomNumber = new Random();
/// <summary> /// Generate a random string using the default options /// </summary> /// <returns>the random string</returns> public string GenerateRandomString() { return GenerateRandomString(CONST_MaxStringLenght); }
/// <summary> /// Create a random string based on a specified lenght /// </summary> /// <param name="lenght">the lenght of the desired lenght of the random string</param> /// <returns>the randomized string</returns> public string GenerateRandomString(int lenght) { return GenerateRandomString(lenght, CreateRandomStringSet()); }
/// <summary> /// Creates a random string based on a specific lenght and character set /// </summary> /// <param name="lenght">the lenght of the desired lenght of the random string</param> /// <param name="charsToUse">character set to use</param> /// <param name="randomizeSourceSet">defines whether the source set should be scrambled</param> /// <returns>the random string</returns> public string GenerateRandomString(int lenght, string charsToUse, bool randomizeSourceSet) { string randomString = String.Empty;
if (randomizeSourceSet) { //scramble and jumble it randomString = GenerateRandomString(lenght, CreateRandomStringSet(charsToUse)); } else { //use the default charset randomString = GenerateRandomString(lenght, charsToUse); }
return randomString; }
/// <summary> /// Creates a random string based on a specific lenght and character set /// </summary> /// <param name="lenght">the lenght of the desired lenght of the random string</param> /// <param name="charsToUse">character set to use</param> /// <returns>the random string</returns> public string GenerateRandomString(int lenght, string charsToUse) { //Create a new StringBuilder that would hold the random string. StringBuilder randomString = new StringBuilder();
//Create a variable to hold the generated charater. char appendedChar;
//Create a loop that would iterate from 0 to the specified value of intLenghtOfString for (int i = 0; i <= lenght; ++i) { int characterIndex = Convert.ToInt32(randomNumber.Next(i, charsToUse.Length - i)); //Generate the char and assign it to appendedChar appendedChar = charsToUse[characterIndex]; //Append appendedChar to randomString randomString.Append(appendedChar); } //Convert randomString to String and return the result. return randomString.ToString(); }
/// <summary> /// Returns a random set of characters based on the default literal set /// </summary> /// <returns>the random string</returns> private string CreateRandomStringSet() { //just use the default character set return CreateRandomStringSet(CONST_AllowedCharacterLiterals); }
/// <summary> /// A function that returns a new set of characters based on an input set /// </summary> /// <param name="allowedCharacters">the source set</param> /// <returns>the new collection of characters</returns> private string CreateRandomStringSet(string allowedCharacters) { string randomizedString = String.Empty;
//get a random string set size int randomSetLenght = allowedCharacters.Length * randomNumber.Next(1, CONST_MaxStringLenght);
//while lenght of the random set is not the same as the source string lenght while (randomizedString.Length != randomSetLenght) { //add a new character randomizedString += GetRandomCharFromString(allowedCharacters); }
//return our random string return randomizedString; }
/// <summary> /// Gets a character from the the input string /// </summary> /// <param name="allowedCharacters">source string</param> /// <returns>a random character</returns> private char GetRandomCharFromString(string allowedCharacters) { return allowedCharacters[randomNumber.Next(allowedCharacters.Length - 1)]; } } }
[----------------- C# Usage -----------------]
using System; using System.Collections.Generic; using System.Text;
namespace KeithRull.ConsoleCentral { class Program { static void Main(string[] args) { RandomStrings r = new RandomStrings();
Console.WriteLine(r.GenerateRandomString()); Console.WriteLine(r.GenerateRandomString(10)); Console.WriteLine(r.GenerateRandomString(10, "qwerttyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM")); Console.WriteLine(r.GenerateRandomString(10, "[]{}<>!@#$%^&*()qwerttyuioplkjhgfdsazxcvbnm1234567890", true)); Console.WriteLine(r.GenerateRandomString(10, "qwerttyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM", false));
Console.ReadLine(); } } }
[----------------- VB.NET Version -----------------]
Imports System Imports System.Collections.Generic Imports System.Text
Namespace KeithRull.ConsoleCentral Class RandomStrings Private Const CONST_MaxStringLenght As Integer = 10 Private Const CONST_AllowedCharacterLiterals As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
Private randomNumber As New Random()
''' <summary> ''' Generate a random string using the default options ''' </summary> ''' <returns>the random string</returns> Public Function GenerateRandomString() As String Return GenerateRandomString(CONST_MaxStringLenght) End Function
''' <summary> ''' Create a random string based on a specified lenght ''' </summary> ''' <param name="lenght">the lenght of the desired lenght of the random string</param> ''' <returns>a random string</returns> Public Function GenerateRandomString(ByVal lenght As Integer) As String Return GenerateRandomString(lenght, CreateRandomStringSet()) End Function
''' <summary> ''' Creates a random string based on a specific lenght and character set ''' </summary> ''' <param name="lenght">the lenght of the desired lenght of the random string</param> ''' <param name="charsToUse">character set to use</param> ''' <param name="randomizeSourceSet">defines whether the source set should be scrambled</param> ''' <returns></returns> Public Function GenerateRandomString(ByVal lenght As Integer, ByVal charsToUse As String, ByVal randomizeSourceSet As Boolean) As String Dim randomString As String = [String].Empty
If randomizeSourceSet Then 'scramble and jumble it randomString = GenerateRandomString(lenght, CreateRandomStringSet(charsToUse)) Else 'use the default charset randomString = GenerateRandomString(lenght, charsToUse) End If
Return randomString End Function
Public Function GenerateRandomString(ByVal lenght As Integer, ByVal charsToUse As String) As String 'Create a new StringBuilder that would hold the random string. Dim randomString As New StringBuilder()
'Create a variable to hold the generated charater. Dim appendedChar As Char For i As Integer = 0 To lenght
'Create a loop that would iterate from 0 to the specified value of intLenghtOfString Dim characterIndex As Integer = Convert.ToInt32(randomNumber.[Next](i, charsToUse.Length - i)) 'Generate the char and assign it to appendedChar appendedChar = charsToUse(characterIndex) 'Append appendedChar to randomString randomString.Append(appendedChar) Next 'Convert randomString to String and return the result. Return randomString.ToString() End Function
''' <summary> ''' Returns a random set of characters based on the default literal set ''' </summary> ''' <returns></returns> Private Function CreateRandomStringSet() As String Return CreateRandomStringSet(CONST_AllowedCharacterLiterals) End Function
''' <summary> ''' A function that returns a new set of characters based on an input set ''' </summary> ''' <param name="allowedCharacters">the source set</param> ''' <returns>the new collection of characters</returns> Private Function CreateRandomStringSet(ByVal allowedCharacters As String) As String Dim randomizedString As String = [String].Empty
'get a random string set size Dim randomSetLenght As Integer = allowedCharacters.Length * randomNumber.[Next](1, CONST_MaxStringLenght)
'while lenght of the random set is not the same as the source string lenght While randomizedString.Length <> randomSetLenght 'add a new character randomizedString += GetRandomCharFromString(allowedCharacters) End While
'return our random string Return randomizedString End Function
''' <summary> ''' Gets a character from the the input string ''' </summary> ''' <param name="allowedCharacters">source string</param> ''' <returns>a random character</returns> Private Function GetRandomCharFromString(ByVal allowedCharacters As String) As Char Return allowedCharacters(randomNumber.[Next](allowedCharacters.Length - 1)) End Function End Class End Namespace
[----------------- VB.NET Usage -----------------]
Imports System Imports System.Collections.Generic Imports System.Text
Namespace KeithRull.ConsoleCentral Class Program Private Shared Sub Main(ByVal args As String()) Dim r As RandomStrings = New RandomStrings()
Console.WriteLine(r.GenerateRandomString()) Console.WriteLine(r.GenerateRandomString(10)) Console.WriteLine(r.GenerateRandomString(10, "qwerttyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM")) Console.WriteLine(r.GenerateRandomString(10, "[]{}<>!@#$%^&*()qwerttyuioplkjhgfdsazxcvbnm1234567890", True)) Console.WriteLine(r.GenerateRandomString(10, "qwerttyuioplkjhgfdsazxcvbnm1234567890QWERTYUIOPLKJHGFDSAZXCVBNM", False))
Console.ReadLine() End Sub End Class End Namespace
[----------------- Screenshot -----------------]

And that's how you create random strings in C# and VB.NET. Interested in the source code? You can download them here. RandomStrings.cs (4.61 KB) | RandomStrings.vb (5 KB)
I've just finished downloading Microsoft Visual Studio 2008 bits last night and I think I'm about ready to install it on my VPC (yup, I don't want to install it yet on my real machine.). I'm really excited about this new release since it looks really really promising. I've seen blogs giving it high praise and some not giving it a nod of acceptance(a few I should say) but for me it's the best Visual Studio to come out yet. I've been playing with the beta version since last year and really happy with this new release from the VS Team.
I know there are several things to consider before you install this version and I'm really glad that Jon made this list to keep as sane when installing/upgrading to Visual studio 2008. Great job Jon!
Now I'm ready to rock!

Sounds like Woody, Lynn, Jason, Tim, Anand, Rob, Mithun and JD are going to hit the road with there Microsoft Truck this 2008.
What's a Code Trip? Think of it like Cannonball Run. Only slower, and geekier. We sat around on a campfire burning copies of Microsoft Bob a while back and decided we needed to hit the streets. We want to get out to developers and hear some stories and have some fun (JD wants to blow stuff up, so we're trying to work that in). Really, it is going to be what you tell us it is. One RV, bunch of geeks, lots o' code. Join the trip!
This is going to be awesome. I go to MS conferences alot and have met a couple of MS Developer Evangelist in the past (specially those who are in the SoCal area) and I think it's a great time for me to meet the other MS Developer Evangelist who cover the west coast.
Hey Woody! Can you reserve me one of those XBOX 360 :D I think that would look great in our living room :P Just kidding.
I just saw this because Jojo Paderes had his status in GTalk pointing to this link.
According to Mercer, the Philippines is still one of the cheapest IT outsourcing destination in the world. The figures states that as of 2007 IT Managers in Manila only earn $22,280/year on an averaged ranking third compared to Switzerland, the highest paying country which has their IT managers average a whooping $140,960/year[link].
|
Figure 1* |
| IT Manager: 10 top-paying countries (various currencies) |
| |
|
Local |
USD |
EUR |
GBP |
| 1 |
Switzerland |
176,920 |
140,960 |
110,990 |
74,150 |
| 2 |
Denmark |
722,310 |
123,080 |
96,890 |
64,750 |
| 3 |
Belgium |
95,380 |
121,170 |
95,380 |
63,760 |
| 4 |
UK |
62,180 |
118,190 |
93,090 |
62,180 |
| 5 |
Ireland |
85,200 |
108,230 |
85,200 |
56,950 |
| 6 |
US |
107,500 |
107,500 |
84,650 |
56,550 |
| 7 |
Germany |
84,020 |
106,730 |
84,020 |
56,160 |
| 8 |
Canada |
106,000 |
93,860 |
73,870 |
49,370 |
| 9 |
Hong Kong (China) |
702,720 |
90,340 |
71,120 |
47,530 |
| 10 |
Australia |
115,480 |
88,850 |
69,950 |
46,740 | |
| Figure 2* |
|
| IT Manager: 10 lowest-paying countries (various currencies) |
|
|
Local |
USD |
EUR |
GBP |
| 1 |
Vietnam |
15,470 |
15,470 |
12,180 |
8,140 |
| 2 |
Bulgaria |
34,25o |
22,240 |
17,510 |
11,700 |
| 3 |
Philippines |
1,106,700 |
22,280 |
17,540 |
11,720 |
| 4 |
India |
1,120,490 |
25,000 |
19,680 |
13,150 |
| 5 |
Indonesia |
289,155,000 |
31,720 |
24,970 |
16,690 |
| 6 |
China (Shanghai) |
265,810 |
33,770 |
26,580 |
17,770 |
| 7 |
Malaysia |
129,930 |
35,260 |
28,040 |
18,740 |
| 8 |
Czech Republic |
791,430 |
35,880 |
28,250 |
18,880 |
| 9 |
China (Beijing) |
285,130 |
36,220 |
28,520 |
19,060 |
| 10 |
Argentina |
133,040 |
43,180 |
33,990 |
22,720 | |
| Figure 3* |
Figure 4* |
| IT Manager: 5 highest paying positions in Asia |
| |
|
Local |
USD |
| 1 |
Hong Kong |
1 702,723.00 |
90,344.03 |
| 2 |
Australia |
2 115,483.00 |
88,846.75 |
| 3 |
Japan |
3 10,347,000.00 |
87,638.17 |
| 4 |
South Korea |
4 69,374,000.00 |
74,022.62 |
| 5 |
Singapore |
5 104,127.00 |
66,615.70 | |
| IT Manager: 5 lowest paying positions in Asia |
| |
|
Local |
USD |
| 1 |
Vietnam |
1 15,473.00 |
15,473.00 |
| 2 |
Philippines |
2 1,106,700.00 |
22,281.05 |
| 3 |
India |
3 1,120,486.00 |
24,996.90 |
| 4 |
Indonesia |
4 289,155,000.00 |
31,721.24 |
| 5 |
China - Shanghai |
5 265,814.00 |
33,768.74 | |
*Note:
-
Average total cash compensation includes base pay and annual bonus.
-
Foreign exchange conversions were made as of November 2006.
-
Source: Mercer: 2007 IT Pay around the World. |
You can treat the numbers above in different ways... either Manila is not getting the big piece of the pie because we are undervalued (considering that we are the largest english speaking nation in Asia) or... That we can attract more companies to outsource to Manila because we are talented and cheap enough to do projects for other countries which means a larger economic growth for our country.
I think the numbers above would fluctuate specially knowing that the US Dollar is currently in a slow decline and Euro starting to dominate the markets.
The Philippines has a great talent pool when it comes to IT and most of the them work hard to hone their s |