Question

I have an abstract class method:

Public Class Base_BLL
{
    Public Overridable Function Persist(ByRef x As Base_BO) As Base_BO
    {
    }
}

Public CLass ActualBLL Inherits Base_BLL
{
}

public Class Main_BO Inherits Base_BO
{
}

I am reusing old vb code, and have a C# presenter class which is trying to persist the Main_BO class using the ActualBLL method. But I can't get it to compile:

ActualBLL bll = new ActualBLL()
Main_BO bo = new Main_BO()
bo.ID="3"
bo = bll.Persist(ref bo)

Compiler doesn't like it one bit. However, in VB the following line compiles fine:

bo = bll.Persist(bo);

I'm at a bit of a loss here...

Was it helpful?

Solution

The C# compiler is stricter, it does not insert these casts for you.

Main_BO bo = new Main_BO() ;
// ...
Base_BO br = bo ;
bo = (Main_BO) bll.Persist (ref br) ;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top