# Sunday, 18 June 2006

A lot of people, myself included, like to see the line numbers on each line while coding. I find it easer to remember where my code is but also to use the ctrl + g (goto line number) shortcut. By default this feature is disabled but luckely it's quite easy to turn it on.

Just navigate to the menu, choose Tools | Options and this expand the Text editor node in the treeview on the left like shown in Figure 1:


Figure 1: The expanded Text Editor part

There you can choose the All languages node or the node of the language that you're interested in and check the Line numbers checkbox. Click the OK button and you have the line numbers appearing in your source view.

Grz, Kris.

Sunday, 18 June 2006 18:23:51 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 

Nullable types in .NET 2.0 are a great asset for many developers. I use them all the time in my current project. However there are some things that you should be aware of. Because they can be filled in or can be null you should perform some extra checks in order to get your code to behave like you would expect it.

I've written some sample code that uses a nullable DateTime endDate. In applications this can be used to denote a period, startDate - endDate with the endDate being as such that it will never expire. In .NET 1.x we would've just filled it up with new DateTime(9999, 12, 31);. With nullable types you can just let it be null and check appropriately.

    1 <%@ Page Language="C#"%>

    2 

    3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    4 

    5 <script runat="server">

    6 

    7     protected void Page_Load(object sender, EventArgs e)

    8     {

    9         DateTime startDate = newDateTime(2004, 5, 23);

   10 

   11         // Using a nullable DateTime can represent an occurance that doesn't expire.

   12         // In a database, like SQL Server, you can have this field set to NULL.

   13         DateTime? endDate = null;

   14         DateTime toCheck = newDateTime(2006, 6, 13);

   15 

   16         // First example: this test will fail because we check

   17         // a normal DateTime against a nullable DateTime without

   18         // replacing it with something to check against when it's null.

   19         // Note however that this code compiles! It's only not working out

   20         // in a functional logic way because it doesn't do what we would expect.

   21         if (startDate <= toCheck && toCheck < endDate)

   22             LabelEndDateNull.Text = true.ToString();

   23         else

   24             LabelEndDateNull.Text = false.ToString();

   25 

   26 

   27         // Second example: now we're checking, and replacing it with an appropriate

   28         // value in case it's null, so the test will pass as expected.

   29         // The trick here is to use the GetValueOrDefault() method on a Nullable type

   30         // to replace it with a default value in case it's null.

   31         if (startDate <= toCheck && toCheck < endDate.GetValueOrDefault(DateTime.MaxValue))

   32             LabelEndDateNullButWithGetValueOrDefaultUsage.Text = true.ToString();

   33         else

   34             LabelEndDateNullButWithGetValueOrDefaultUsage.Text = false.ToString();

   35 

   36         // Third example: this one's exactly the same as the previous, second, example.

   37         // Only here I'm applying the great ?? operator available in C# 2.0.

   38         if (startDate <= toCheck && toCheck < (endDate ?? DateTime.MaxValue))

   39             LabelEndDateNullButWithCheck.Text = true.ToString();

   40         else

   41             LabelEndDateNullButWithCheck.Text = false.ToString();

   42 

   43 

   44         // Fourth example: fill up the nullable DateTime with some actual value:

   45         endDate = newDateTime(2007, 1, 1);

   46 

   47         // We can see, this is easier when done debugging the code, that the enddate

   48         // now has some actual value and the test will pass.

   49         if (startDate <= toCheck && toCheck < (endDate ?? DateTime.MaxValue))

   50             LabelEndDateNotNull.Text = true.ToString();

   51         else

   52             LabelEndDateNotNull.Text = false.ToString();

   53     }

   54 

   55 </script>

   56 

   57 <html xmlns="http://www.w3.org/1999/xhtml">

   58 <head runat="server">

   59     <title>Untitled Page</title>

   60 </head>

   61 <body>

   62     <form id="form1" runat="server">

   63     <div>

   64         Enddate = null:

   65         <asp:Label ID="LabelEndDateNull" runat="server"></asp:Label>

   66         <br/>

   67         <br/>

   68         Enddate = null but with GetValueOrDefault method:

   69         <asp:Label ID="LabelEndDateNullButWithGetValueOrDefaultUsage" runat="server"></asp:Label>

   70         <br/>

   71         <br/>

   72         Enddate = null but with ?? check:

   73         <asp:Label ID="LabelEndDateNullButWithCheck" runat="server"></asp:Label><br/>

   74         <br/>

   75         EndDate != null:

   76         <asp:Label ID="LabelEndDateNotNull" runat="server"></asp:Label></div>

   77     </form>

   78 </body>

   79 </html>

The output of this little code sample is:

Enddate = null: False

Enddate = null but with GetValueOrDefault method: True

Enddate = null but with ?? check: True

EndDate != null: True

 

Take a look at the comment in the code, or better yet: debug it on your own dev machine, to see the subtle difference between the first and second example. The third example's just the same as the second but uses the ?? operator, the one that I prefer in my code because its shorter. The ?? operator, or null coalescing operator, is only available in C# 2.0.

Grz, Kris.

kick it on DotNetKicks.com

Sunday, 18 June 2006 13:01:24 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 

I'm probably very late with this but finally decided to join del.icio.us so finally people can also see what I like to read or am interested in.

For people who don't know this service:

del.icio.us is a collection of favorites - yours and everyone else's. Use del.icio.us to:

  • Keep links to your favorite articles, blogs, music, restaurant reviews, and more on del.icio.us and access them from any computer on the web.
  • Share favorites with friends, family, and colleagues.
  • Discover new things. Everything on del.icio.us is someone's favorite - they've already done the work of finding it. Explore and enjoy.

Grz, Kris.

Sunday, 18 June 2006 10:43:06 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 13 June 2006

I just found out about the existence of this newly dedicated site: netfx3. After blogging already about the renamed WinFX to .NET 3.0 framework name it seems Microsoft's dedicated to the new naming.

Grz, Kris.

Links | Vista | WCF | WCS | WF | WPF
Tuesday, 13 June 2006 15:55:06 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [2]  | 
# Monday, 12 June 2006

Just saw that Scott Mitchell, of 4guysfromrolla fame, announced that he's busy writing tutorials about working with data in ASP.NET 2.0. You can find the tutorials in the Learn section of the ASP.NET official site among other tutorials like videos's, starter kits, ... Be sure to check out the Working with data in ASP.NET 2.0 tutorials. They're also downloadable in pdf format in both VB.NET and C#.

Grz, Kris.

Monday, 12 June 2006 21:08:05 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Saturday, 10 June 2006

Just read .NET Framework 3.0 at Somasegar's blog.

It's just rebranding of the name Microsoft pushed as WinFX, because behind the scenes it seems to be the same .NET 2.0 framework as we're having now, but with added value: Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), Windows Workflow Foundation (WF) and Windows CardSpace (WCS).

I'm already looking forward to .NET 4.0. Are you?

Update: another article by Brad Abrams is online too: Toward .NET Framework 3.0....

Grz, Kris.

Vista | WCF | WCS | WF | WPF
Saturday, 10 June 2006 08:14:10 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Friday, 09 June 2006
Just found out Microsoft started with a Wiki: MSDN Wiki. They'll hope to get more examples form the community and by thus more information for other people. Sounds like a good idea but I guess it'll have to grow before it becomes succesfull.

Grz, Kris.

Friday, 09 June 2006 18:11:55 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 07 June 2006

Thanks to the newly added service by Microsoft in Belgium, I was told that this service was already longer available for other countries, called MSDN Connection one can purchase every month a book of the month at a 40% discount. Today I bought those of May and June:

May:

$blank(www.microsoft.com/mspress/books/6522.asp,CLR via C# Second Edition)

June:

$blank(www.microsoft.com/MSPress/books/8377.asp,Programming Microsoft ASP.NET 2.0 Applications: Advanced Topics)

The weather's finally getting better in Belgium so I can relax and read some interesting stuff the next couple of weeks.

Grz, Kris.

Wednesday, 07 June 2006 18:11:02 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 06 June 2006

Most people are getting aware of the new upcoming version of Office. There are already several resources available and I thought I'd list some:

Some videos: Channel 9 In the office
Some report by Forrester: Developers get ready for 2007 Office system
A quick introduction to the new UI of 2007 Office System: First look 2007 Office System
extension code samples, supplemental developer white papers: 2007 Office System Starter Kit: Enterprise Content Management Starter Kit

Grz, Kris.

Tuesday, 06 June 2006 20:02:40 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [1]  | 

Anyone who knows me, knows that I like Star Wars. I was quite amused when I found out about this little flash movie: Store Wars.

Grz, Kris.

Tuesday, 06 June 2006 19:12:23 (GMT Daylight Time, UTC+01:00)  #    Disclaimer  |  Comments [0]  |