Friday, January 28, 2005

Do you ever had troubles to answer questoin's at a job interview?? Try the follwing website, may it help.

- TechInterviews.com

Saturday, January 15, 2005

Do you have a problem to Debug WebSolutions after .Net 2.0?

Well, after a whole evening i found out the solution to this problem.

- Open Computer Managment
- Choose IIS-> Web Sites-> Default Web Sites
- Choose your Web and open the Properties

You can see the additional Tab: ASP.NET

Just change now from 1.1.XXXXX to 2.0.XXXXXX.

Enjoy to go on with .Net 1.1

Tuesday, January 11, 2005

Customised sorting of an ArrayList (C#)


A handy feature that was included in ArrayList's, is the ability to sort the list according to your own comparison criteria. Unfortunately the documentation is a bit scarce on exactly how to implement this, of which an example wouldn't have gone awry.

The first thing you need to start with is the object to store in your ArrayList, for this example I have put together a simple object call Person (Person.cs). This object one contains two member variables, Name and Age.

using System;

namespace SortArrayListCS {

public class Person {
public string Name;
public int Age;

public Person() {
}

public Person(string name, int age) {
this.Name = name;
this.Age = age;
}
}
}

Now we need to implement the infamous IComparer interface to define how we want to sort this. Whilst I have made this a little more elaborate than it need be, I wanted to show how you can further define how you want to sort this collection.

Our comparer is called PersonComparer (PersonComparer.cs), and we also have a enum called SortDirection which allows us to define whether we want to sort Ascending or Descending.

using System;
using System.Collections;

namespace SortArrayListCS {

public enum SortDirection {
Ascending,
Descending
}

public class PersonComparer : IComparer {

private SortDirection m_direction = SortDirection.Ascending;

public PersonComparer() : base() { }

public PersonComparer(SortDirection direction) {
this.m_direction = direction;
}

int IComparer.Compare(object x, object y) {

Person personX = (Person) x;
Person personY = (Person) y;

if (personX == null && personY == null) {
return 0;
} else if (personX == null && personY != null) {
return (this.m_direction == SortDirection.Ascending) ? -1 : 1;
} else if (personX != null && personY == null) {
return (this.m_direction == SortDirection.Ascending) ? 1 : -1;
} else {
return (this.m_direction == SortDirection.Ascending) ?
personX.Age.CompareTo(personY.Age) :
personY.Age.CompareTo(personX.Age);
}
}
}
}

If you wanted to sort an ArrayList of mismatched objects which have a common field, you would design an interface that each of those objects implement, then change the comparer to cast these objects as their interface.

Finally we need to test this to make sure everything is working as it seems. I knocked this together as a Console Project (C#) just to be quick and simple, so our test file is SortArrayList.cs.

using System;
using System.Collections;

namespace SortArrayListCS {

class SortArrayList {

[STAThread]
static void Main(string[] args) {

ArrayList list = new ArrayList();
list.Add(new Person("John", 50));
list.Add(new Person("Mary", 28));
list.Add(new Person("William", 12));
list.Add(new Person("Marcia", 17));
list.Add(new Person("Rodrick", 36));

list.Sort(new PersonComparer());

Console.WriteLine("Sort Ascending");
foreach (Person person in list) {
Console.WriteLine("Name: " + person.Name + ", Age: " + person.Age.ToString());
}

list.Sort(new PersonComparer(SortDirection.Descending));

Console.WriteLine("\n\rSort Descending");
foreach (Person person in list) {
Console.WriteLine("Name: " + person.Name + ", Age: " + person.Age.ToString());
}

Console.ReadLine();
}

}
}

If all of this worked as planned you should see the following output:

Sort Ascending
Name: William, Age: 12
Name: Marcia, Age: 17
Name: Mary, Age: 28
Name: Rodrick, Age: 36
Name: John, Age: 50

Sort Descending
Name: John, Age: 50
Name: Rodrick, Age: 36
Name: Mary, Age: 28
Name: Marcia, Age: 17
Name: William, Age: 12




===============================================================================
Maybe it wouldn't a better choice to avoid overhead/exceptions from trying to cast null's be:

int IComparer.Compare(object x, object y) {

if (x == null && y == null) return 0;
if (x == null && y != null)
return (this.m_direction == SortDirection.Ascending) ? -1 : 1;
if (x != null && y == null)
return (this.m_direction == SortDirection.Ascending) ? 1 : -1;

Person personX = (Person) x;
Person personY = (Person) y;

return (this.m_direction == SortDirection.Ascending) ?
personX.Age.CompareTo(personY.Age) :
personY.Age.CompareTo(personX.Age);
}
}
}
}

do you search a tip? please choose a category.

Tips

Loading assemblies by Reflection

MSD2D is a community site for Exchange, SharePoint, .NET and Security support.

Friday, January 07, 2005

Tekst

Das ist ja richtig interessant.

Tekst

Thursday, January 06, 2005

register dll; register ocx -> make it easy -> regsvr32.exe

just create copy the following text to a *.reg file and execute it. Right mouse click and choose Register or Un-Register. Enjoy it.

=========== START =============
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.dll]@="dllfile"
[HKEY_CLASSES_ROOT\.ocx]@="ocxfile"
[HKEY_CLASSES_ROOT\dllfile]"EditFlags"=dword:00000000"BrowserFlags"=dword:00000008@="Programmbibliothek"
[HKEY_CLASSES_ROOT\dllfile\DefaultIcon]@="shell32.dll,72"
[HKEY_CLASSES_ROOT\dllfile\shell]@="Registrierung"
[HKEY_CLASSES_ROOT\dllfile\shell\Register DLL]
[HKEY_CLASSES_ROOT\dllfile\shell\Register DLL\command]@="c:\\windows\\system32\\regsvr32.exe \"%1\""
[HKEY_CLASSES_ROOT\dllfile\shell\Un-Register DLL]
[HKEY_CLASSES_ROOT\dllfile\shell\Un-Register DLL\command]@="c:\\windows\\system32\\regsvr32.exe \"%1\" /u"
[HKEY_CLASSES_ROOT\ocxfile]"EditFlags"=dword:00000000"BrowserFlags"=dword:00000008@="ActiveX-Control"
[HKEY_CLASSES_ROOT\ocxfile\DefaultIcon]@="shell32.dll,21"
[HKEY_CLASSES_ROOT\ocxfile\shell]@="Registrierung"
[HKEY_CLASSES_ROOT\ocxfile\shell\Register Active-X]
[HKEY_CLASSES_ROOT\ocxfile\shell\Register Active-X\command]@="c:\\windows\\system32\\regsvr32.exe \"%1\""
[HKEY_CLASSES_ROOT\ocxfile\shell\Un-Register Active-X]
[HKEY_CLASSES_ROOT\ocxfile\shell\Un-Register Active-X\command]@="c:\\windows\\system32\\regsvr32.exe \"%1\" /u"
=========== END ===============

Shared Cache - .Net Caching made easy

All information about Shared Cache is available here: http://www.sharedcache.com/. Its free and easy to use, we provide all sources at codeplex.

Facebook Badge