September 2005 - Posts

There is a new type called var in C# 3.0.  Var simply means that the compiler infers the type from whatever you assign to it.  Before I start, it is not a variant and it is not something that is loosely typed.
Take these examples (pre C# 3.0):
string myString = “hello”;
int myInt = 5;
float myFloat = 5.5f;
Here is how they can be represented in C# 3.0:
var myString = “hello”;
var myInt = 5;
var myFloat = 5.5f;
In this case, myString is declared as a string when it comes down to it.  If you later try to assign an int to it, you would get an error.  The power of this is that you can create whole new data types dynamically without having to actually create them first.
This is one of the primary technologies used in Language Integrated Query (LINQ).  There are several more things like this that I will show you soon.  The article below provides even more detail.
As I might have pointed out in the past, the ConfigurationSettings object is deprecated and has been replaced with the ConfigurationManager object.  This object gives you direct access to sections of the web.config or machine.config including the new <connectionStrings> section.  Sometimes when you try to use it, you may notice it doesn't compile or work with intellisense.  This is because they moved the configuration classes out of System.dll and into the new System.Configuration.dll.  So therefore, if you want to make use of it you have to include that reference in your project. 

The syntax is the same as the ConfigurationSettings class.
As I suspected, the WinFX September CTP only works on Beta 2.  This blog entry describes which products from the PDC work together.
In ASP.NET 2.0, the use of resource files actually does not suck any more.  In fact it is pretty cool and will allow us to do everything we have done in the past plus probably more.  The first thing is that resources are now strongly typed.  For example if you create a new resource file called MyResources with a key of HelloWorld, the resource can be accessed programmatically by the line below.
MyTextBox.Text  = Resources.MyResources.HellowWorld;
The value of resources can also be accessed by using an expression inside your markup.
<%$ Resources:MyResources,HelloWorld %>
On top of that if you want to bind the value of a resource to a control, you can use the meta:resourcekey attribute.
<asp:Label ID="Label1" runat="server" 
meta:resourcekey="resource-key-prefix" /> 
The limitation there is that it only works with local resources (lame).  There are two types of resources global and local.  Local are specific to a particular page (i.e.: index.aspx.resx) and are contained in the App_LocalResources folder.  Global Resources can be used anywhere and are stored in the App_GlobalResources folder.
Cultures can be autodetected by using a compiler directive or can be overridden and set manually by overriding the InitializeCulture event.  In this event you can set the culture with a statement like this.
Thread.CurrentThread.CurrentCulture = 
There is a good chance we will start using resources in ASP.NET 2.0 as opposed to our own proprietary solution.  We sitll may have to do some tweaking but I think it will provide us a good foundation.
Obviously, coming back from last week I have a ton to talk about over the next couple of days.  First and foremost is that we get everone upgraded to RC1 of Visual Studio 2005.  Here are the uninstallation instructions.
If you didn't notice like me, they already have an auto-uninstall tool. 
The installation of SourceSafe is no longer integrated with Visual Studio.  Kevin has discovered that the location of Source Safe is in the VSS folder on the Release Candidate DVD.
Want a cool WinFX reference poster like the one in my cube?  Well, now you don't have to steal mine, you can print out your own.  
Beta 1 of Office 12 will be available in "a couple of months".  If you want to register to join the beta, go to, sign in with your passport, and then use GuestID: PDCOffice (it is case sensitive).  Then just fill out the survey and wait.
One of the new innovations coming in C# 3.0 is the concept of Language Integrated Query. This bridges the gap between a programming language like C# and T-SQL. It introduces a form of syntax that will probably look pretty alien to you at first. This won't be around under the next version of Visaul Studio (next year when Vista comes out), but its good to know what it is.
Here is an example query.
IEnumerable<string> expr = from s in names  where s.Length == 5
 orderby s
 select s.ToUpper();
At some point I will go into more detail of how it works once I fully understand it, but if you are interested in reading more about it, the article below is the place to start.
We have a ton of static pages on our sites. Most of these could probably be cached with similar parameters (i.e.: VaryByParam: none, CacheDuration="60" or whatever). Now the OutputCache compiler directive supports the new CacheProfile attribute. This says go find that profile in the web/machine.config and use those settings.
For example:
<%@ OutputCache CacheProfile="CacheDaily" VaryByParam="name" %>
Then the web.config would have something like:
<add name="CacheDaily" duration="86400" />
If you are curious, the final version of the .NET Framework 2.0 has been announced as being v2.0.50727.