June 2009 Entries

 

Here are the 2 common patterns in .NET:

GIVEN:

 

PATTERN #1:

Note: this method will work with collections that are typed, but not necessarily defined in a class which manages  enumeration

string itemName;

for (int index = 0; index < OrderList.Count;index++)

{

    itemName = OrderList[index].ItemName;

   // do stuff here

}

PATTERN  #2

 

using System;
using System.Collections.Generic;
using System.Text;

namespace AskPaulaExamples
{
    public class Whine
    {
       // define AND dub the collection with something
       List<string> OrderList = new List<string>() {"Gloves","Purse","Hat","Skirt","Gown"};

       static void Main()
       {
           Whine wailAbout = new Whine();

           wailAbout.StuffForMe();
          
       }

       public void StuffForMe()
       {
           IList<string> MyDemands = OrderList.AsReadOnly();
           foreach (string Item in MyDemands)
           {
               Console.WriteLine("What I want for my BIRTHDAY: " + Item.ToString());
           }
       }
       

     }
}

 

If you're getting this message:

The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\Documents and Settings\pldital\My Documents\Visual Studio 2008\Projects\PatentableServices\Transform\PetabyteCompression.svc.cs 

... add...  System.Data.Linq as a reference to your project.

I still get bit every once in awhile (read: pasting together a poc) when I include a LINQ project in a solution were I've got a dependency !