... all I'm offering is the truth. Nothing more. RSS 2.0
# Monday, December 03, 2007

After Robert mentioned that we will be moving to a newer version of the .NET framework, I wanted the opportunity to look at some of the language improvements of .NET 2.0 specifically the use of nullable types.

 

There are two main types that we generally deal with, reference and value types. These two types are treated and stored differently and as a result we have specific behaviors that go along with these types. The main difference I would like to highlight is the fact that value types cannot be null.

So for example:-

int x = 0; //legal
int x = null; // not so legal "Cannot convert null to 'int' because it is a value type"
string s = "hello"; //legal
string s = null; //legal

The surface response is that integers are never null ... but development with XSD and Sql Server allows  us to have nullable integers. So there are legitimate reasons to have a strong solution for this problem of null values.

 

The first way we could do this is to actually create a class that wraps round the integer type. This class would support a series of methods that would checks for Null values. I saw a great VB 6 developer do a similar thing. However, this approach is made redundant in .NET 2.0.

 

Nullable Template:
The more appropriate way to do this would be to use the new Nullable struct This gives us the following:

Nullable<int> i = null; //legal

We can also use HasValue to determine whether the current value is null as follows:

Nullable<int> i = null
if(i.HasValue)  //(also i==null would work)
{
    int j = (int)i;
}

This can be rewritten as follows:

int? i = null; // int ? => nullable int
int j = i ?? 0;

Check the last two snippets of code out in ILDASM. It really amounts to the same thing.

Technorati tags:
Monday, December 03, 2007 8:45:50 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
.NET | C#

Microsoft's online MSDN documentation has, for some time, offered a very intuitive way of discovering information about various classes and namespace via direct input into the URL. Effectively you can guess what the location of things you want to look up.

I can for example type the following URL in my browser http://msdn2.microsoft.com/en-us/library/system.io, and get directed to the System.IO namespace documentation. Similarly I can get directly to information on classes by using the same technique. http://msdn2.microsoft.com/en-us/library/system.data.odbc.odbcerror, takes me directly to OdbcError class.

Technorati tags:
Monday, December 03, 2007 8:43:58 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
.NET
# Friday, November 30, 2007

I am always interested in writing one or two lines less and I saw a technique employed quite a lot when using Switch statements in C#. Directly below is the way I have always written the statements. Basically the execution line of the first two statements are identical, however, the case line is quite different.

XmlTextReader xr = new XmlTextReader(@"C:\test\test.xml");
while (!xr.EOF)
{
    switch (xr.NodeType)
    {
        case XmlNodeType.EndElement:
            Console.WriteLine(xr.Name.ToString());
            break;
        case XmlNodeType.Element:
            Console.WriteLine(xr.Name.ToString());
            break;
        case XmlNodeType.Text:
            Console.WriteLine(xr.Value.ToString());
            break;
    }
    xr.Read();
}

As a short cut you can completely eliminate the first line of execution and it associated "break;" statement as follows. Now both lines will execute the same line of code:

XmlTextReader xr = new XmlTextReader(@"C:\test\test.xml");
while (!xr.EOF)
{
    switch (xr.NodeType)
    {
        case XmlNodeType.EndElement:
        case XmlNodeType.Element:
            Console.WriteLine(xr.Name.ToString());
            break;
        case XmlNodeType.Text:
            Console.WriteLine(xr.Value.ToString());
            break;
    }
    xr.Read();
}

I did not like this shortcut for case statements at first, but I realized that it was due to a small portions of my mind that still thinks in VB6. I do not believe there is a "break;" necessary in VB6. In fact the Select Case statement in VB 6 executes only one of several statements based on the value of the expression.

Technorati tags: ,
Friday, November 30, 2007 8:41:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
.NET | C#
# Thursday, November 29, 2007

I was desperate to get a Zune 80, my wife was attempting to get the new iPod, which in principle is fine, but I did not want to support opposing audio and video technologies in our house. So after a fruitless search within the Toledo city limits I attempted to go online with the usual suspects (Best buy and Circuit City) and got nothing.

Out of pure desperation I attempted a search on the Walmart sites with a search radius of 100 miles. I called 3 stores with limited stock and one of those stores had a single Zune 80 left. I hopped into my car and 45 minutes later I was purchasing what appeared to be the only Zune 80 for 100 miles.

If Microsoft was betting on Flash devices then I think they made a mistake, I could not justify buying a Zune 8 @ $200 (which you can find everywhere) when the Zune 80 was retailing for $50 more.

 

Above is my Zune card in PNG form! I found this fascinating site that takes your Zune card and converts it from flash to an image. Really helpful for sites that do not support flash.

Type in the following url: http://card.mygamercard.net/apps/zune/YOURZUNEID.png
Change YOURZUNEID to your Zune ID!

Welcome to the Social!

Technorati tags: , ,
Thursday, November 29, 2007 8:38:33 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
Zune
# Wednesday, November 28, 2007

I have been messing with a few of the more basic principles of reflection recently. The main points include pulling out a list of types from a given assembly and then reviewing the members of those specific Types.

        public static void ReviewTypes()
        {
            // Checking out a specific assembly
            Assembly a = Assembly.Load("Mscorlib.dll");
            Type[] mytypes = a.GetTypes();
            foreach (Type ty in mytypes)
            {
                Console.WriteLine("Type is {0}", ty);
            }

            Console.WriteLine("{0} types have been located", mytypes.Length);
        }

        public static void ReviewMembers()
        {
            // examine a single type
            Type thisType = Type.GetType("System.Reflection.Assembly");
            Console.WriteLine("This Type is {0}", thisType);

            // get all the associated members
            MemberInfo[] mbrInfoAll = thisType.GetMembers();
            foreach (MemberInfo mbrInfoSelect in mbrInfoAll)
            {
                Console.WriteLine("{0} is a {1}", mbrInfoSelect, mbrInfoSelect.MemberType);
            }
            
        }

This type of granular interrogation of types\members at runtime can be very helpful!

 

Technorati tags: , ,
Wednesday, November 28, 2007 8:37:30 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
.NET | C#
# Tuesday, November 13, 2007

The Zune 2 firmware update was well worth the wait, I actually waited up till midnight to get it but it was not available until later that morning.

The podcasting addition has been made more powerful by the wireless synching that I am now able to do. It took a few seconds to setup and now I do not need to connect my Zune to my PC to get the latest Run As Radio or Hanselminutes.

The true Social (as opposed to the original wireless file sharing) aspect of the Zune will be the real selling point. I believe the widget crazy social web sites will love the accessibility of the user information and playlists! While I know Apple has a tradition of creating isolated sandboxes I think it will be in their best interest to follow suit. There world seems to have a veracious appetite for this kind of useless information.

Here is my card: http://social.zune.net/member/MAD7E7E7

On the negative side I did have to deal with what appeared to be the complete destruction of my library. My library was getting scrambled and the artist were appearing under albums they were not associated. Songs were showing up in contradicting locations ... it was a mess. I hit the message boards and found the following solutions.

FOLDER XP - C:\Documents and Settings\<User Name>\Local Settings\Application Data\Microsoft\Zune\
FOLDER Vista - C:\Users\<User Name> AppData\Local\Microsoft\Zune\

  • Exit Zune2 software

  • Rename the following two files in the correct folder above:
    • ren ZuneStore.sdf ZuneStore.sdf.old
    • ren CurrentDatabase_365.wmdb CurrentDatabase_365.wmdb.old
  • Restart Zune2 software and it will rebuild your collection.

Tuesday, November 13, 2007 8:36:58 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] - Trackback
Zune
Blogroll
Statistics
Total Posts: 330
This Year: 18
This Month: 2
This Week: 0
Comments: 30
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Mark Downie
Sign In
All Content © 2010, Mark Downie
DasBlog theme 'Business' created by Christoph De Baene (delarou)