Browsed by
Category: Good practices

Explicit interface implementation

Explicit interface implementation

In C# you have a feature, which java don’t have. It’s called explicit interface implementation.The main use of this feature is to solve problems when you have to implement for example two interfaces which have both unfortunatly a same method signature: namespace testpw.ExplicitInterfaces{    public interface IA    {        void doAction();    }     public interface IB    {        void doAction();    }} The implementation of both interfaces on the same class look now like this: namespace testpw.ExplicitInterfaces{    public class TestImpl : IA, IB    {       …

Read More Read More

Filtering on DataTables

Filtering on DataTables

When you want to apply a filter to your datatable in your dataset, you can use the method Select on the class DataTable. In our current project we use this method very often, also for databinding. Recently I discover an unexpected behaviour. Let’s assume, that our datatable has 4 datarows and we will apply following filter for databinding:0=1 AND Path = ‘C:\bin’ The first expression (0=1) is added by an other method, which checks if any rows should be visible….

Read More Read More

Programming several conditions in C#

Programming several conditions in C#

When you have to programme a piece of code which have several conditions you could do it in the following way: switch(a.name){    case “smith”:        CallHim();         break;    case “doyle”:        SendAMessageToHim();        break;    default:        throw new WriteNotReachableErrorException();} If you couldn’t use constants as conditions, you will implement the logic in the following way: if(a.name == smithObject.ToString()){    CallHim();}else if(a.name == doyleObject.ToString()){    SendAMessageToHim();}else{    throw new WriteNotReachableErrorException();} But if you think now there is now other possibility to implement the logic, wait! I found recently…

Read More Read More