Author Archive

Cornelius J. van Dyk

Born and raised in South Africa during the 70's I got my start in computers when a game on my Sinclair ZX Spectrum crashed, revealing it's BASIC source code. The ZX had a whopping 48K of memory which was considered to be a lot in the Commodore Vic20 era, but more importantly, it had BASIC built into the soft touch keyboard. Teaching myself to program, I coded my first commercial program at age 15.

After graduating high school at 17, I joined the South African Air Force, graduating the Academy and becoming a Pilot with the rank of First Lieutenant by age 20. After serving my country for six years, I made my way back into computer software.

Continuing my education, I graduated Suma Cum Laude from the Computer Training Institute before joining First National Bank where my work won the Smithsonian Award for Technological Innovation in the field of Banking and Insurance. Soon I met Will Coleman from Amdahl SA, who introduced me to a little known programming language named Huron/ObjectStar. As fate would have it, this unknown language and Y2K brought me to the USA in 1998.

I got involved with SharePoint after playing around with the Beta for SharePoint Portal Server 2003. Leaving my career at Rexnord to become a consultant in 2004, I was first awarded the Microsoft Most Valuable Professional Award for SharePoint in 2005, becoming only the 9th MVP for WSS at the time. I fulfilled a life long dream by pledging allegiance to the Flag as a US citizen in 2006. I met the love of my life and became a private consultant in 2008. I was honored to receive my ninth MVP award for SharePoint Server in 2013.

How do I – Sort a list of custom class objects in descending order in C#?

Written by Cornelius J. van Dyk on . Posted in Blog, How Do I...

Suppose we have a custom class defined thus:

    class CustomClass
    {
        public string String1 { get; set; }
        public string String2 { get; set; }
        public string String3 { get; set; }
        public int Int1 { get; set; }
        public int Int2 { get; set; }

        public CustomClass()
        {
            String1 = "";
            String2 = "";
            String3 = "";
            Int1 = 0;
            Int2 = 0;
        }

        public int Calculate()
        {
            return Int1 + Int2;
        }
    }
As we can see, the class initializes it’s variables and has a Calculate() method that simply returns the added value of the two int variables of the class. Now suppose we have a list of these class objects in our app with varying values thus:
    CustomClass MyClass = new CustomClass();
    MyClass.Int1 = 10;
    MyClass.Int2 = 5;
    CustomClass My2ndClass = new CustomClass();
    My2ndClass.Int1 = 7;
    CustomClass My3rdClass = new CustomClass();

    List lst = new List();
    lst.Add(My2ndClass); 
    lst.Add(MyClass);
    lst.Add(My3rdClass);
We now have a list containing 3 of our custom class objects. The first object in the list has an Int1 value of 10. The second has an Int1 value of 5 and the third, given the class’ initialization method, will have an Int1 value of 0. Given the order that we added the class objects to our list, the list, when looking at the Int1 field would look thus: 7, 10, 0 How do we go about sorting this list by any one of the variable fields of the custom class, say Int1 in our case? The built in support for Linq in Visual C# and the .NET Framework, actually makes this very easy. Using a Lambda expression, the task becomes a one liner thus:
  lst = lst.OrderByDescending(x => x.Int1).ToList();
We start with the OrderByDescending() method and then pass the Lambda expression to reference back to the object itself. The x => part of the expression tells C# to reference back to the calling object which in our case is lst. C# will reference back to lst as x which is where the x.Int1 then instructs the OrderByDescending method to use the Int1 field as the value by which to sort, in descending order, the x object which translates to lst. By appending the ToList() method to the back of the statement, C# will take the sorted result and generate a new List<> object which we simply assign back to the original lst variable. If we needed to sort in ascending order we would use the OrderBy() method instead thus making the statement:
 lst = lst.OrderBy(x => x.Int1).ToList();


Cheers
C




image

Fixing Visual Studio 2012 defaults

Written by Cornelius J. van Dyk on . Posted in Annoyances, How Do I...

One of the biggest pet peeves I experienced when switching to Visual Studio 2012 was the fact that the default command buttons were changed.  In going for a cleaner look, many of the main command buttons most developers use most frequently, was removed from the toolbar interface and buried in the menu structure instead.

Personally, the buttons I find myself using most frequently are the Navigate Backwards and Navigate Forwards (image ), Comment Selected Lines and Uncomment Selected Lines (image ) and lastly Increase Line Indent and Decrease Line Indent (image ).

The Navigate functions are still there, but the Comment and Indent functions are buried deep within the Edit/Advanced menu.  While it’s true that the Comment functions do have hot keys attached to them, I hardly consider Ctrl+K,Ctrl+C for a single click to be useful to most developers save the few that know the hotkeys by heart.

As for the Indent commands, they don’t have any hotkeys and you’d have to click through Edit/Advanced/Indent to get the action.  Though small annoyances, these can be addressed by simply adding the commands back to the command bar.  Here’s how to do just that:

  1. Click Tools on the menu bar.
  2. image  
  3. On the popup menu, click “Customize”.
  4. After the Customize dialog window opens, click over to the “Commands” tab.
  5. Select the “Toolbar” radio button.
  6. In the dropdown to the right of the Toolbar radio button, select the “Standard” toolbar to work with.
  7. The toolbar’s controls will be previewed in the bottom left of the dialog window.
  8. To the right of the preview, click the “Add Command” button.
  9. image  
  10. In the Add Command dialog window that opens up, select the “Edit” category to the left.
  11. On the right, scroll down through the commands and locate the “Line Indent” command.
  12. Select the command and click the “OK” button.
  13. image
  14. The command will be added to the top of the Controls preview.
  15. image  
  16. Repeat steps 8 through 12 for the “Line Unindent”, “Selection Comment” and “Selection Uncomment” commands as well.  The interface doesn’t allow multi-select, though that would be nice touch in a future update.
  17. Once you have all the commands, use the “Move Up” and “Move Down” buttons to the right to arrange the commands in the order you wish them to appear on the toolbar.
  18. image  
  19. When you’re happy with the arrangement, click the “Close” button.  Your new toolbar should now reflect your favorite buttons again. 🙂
  20. image


Cheers
C




image