[Solved] How to optimize redundant code in c#?


It is not possible to put generic constraint about specific constructor availabilty, so you cannot guarantee inside the method that TDal _dal = new TDal(_connectionString); is possible.

I would refactor it then to provide dal externally:

public List<TRule> getData<TRule>(TRule perRA, IDal<TRule> dalRA, int acao)
{
    List<TRule> list = new List<TRule>();
    try
    {
        list = dalRA.getDATA(perRA, acao);
    }
    catch (Exception e)
    {
        throw e;
    }
    finally
    {
        dalRA = null;
    }
    return list;
}

assuming:

internal interface IDal<TRule>
{
    List<TRule> getDATA(TRule perRA, int acao);
}

2

solved How to optimize redundant code in c#?