Emil’s Blog

Programming Windows, .Net, EPiServer and whatnot…

[Powered by WordPress.]

March 23, 2006

Array-sorting using generics and anonymous methods

by @ 14:53. Filed under .Net programming

Alternative 1 (type safe sorting using generics):

private int ComparePass(Pass x, Pass y)
{
    if (x.Starttid <y.Starttid) return -1;
    if (x.Starttid> y.Starttid) return 1;
    return 0;
}
:
:
    Pass[] results = ...;
    Array.Sort<Pass>(results, ComparePass);
:

Alternative 2 (type safe sorting using generics and an anonymous method):

Pass[] results = ...;
Array.Sort<Pass>(results,
    delegate(Pass x, Pass y)
    {
        if (x.Starttid <y.Starttid) return -1;
        if (x.Starttid> y.Starttid) return 1;
        return 0;
    });

Alternative 3 (type safe sorting using generics and an anonymous method using a default comparer):

Pass[] results = ...;
Array.Sort<Pass>(results,
    delegate(Pass x, Pass y)
    {
        return Comparer.Default.Compare(x.Starttid, y.Starttid);
    });

March 17, 2006

Draw icon with the alpha channel enabled

by @ 13:59. Filed under .Net programming

Here's how to draw an icon in a control utilizing the icon's built-in alpha channel.

private void cmdEmail_Paint(object sender,
  System.Windows.Forms.PaintEventArgs e)
{
  System.Drawing.Icon icon;
  icon = new Icon(
    GetType().Module.Assembly.GetManifestResourceStream(
      "ActiveSolution.Lernia.SFI.WinClient.Images.mail.ico"),
    16, 16);
  e.Graphics.DrawIcon(icon,0,0);
}

The name of the icon resource is easily found using ildasm. Double-click on the "M A N I F E S T" node and look for the icon in the window that opens.

March 5, 2006

Install XML Schemas in Visual Studio

by @ 12:08. Filed under Visual Studio tips

If you copy xsd-files to C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml (or wherever VS.NET is installed), you will get intellisense and validation in the VS.NET XML editor when editing XML files. In Visual Studio 2005 the directory is C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas.

[powered by WordPress.]

jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.

Internal links:

Categories:

Search blog:

Archives:

March 2006
M T W T F S S
« Feb   Apr »
 12345
6789101112
13141516171819
20212223242526
2728293031  


View Emil Åström's profile on LinkedIn

General links:

I read:

Visitors

Recent Comments

Spam caught

Other:

Clicky Web Analytics

38 queries. 0.806 seconds